<?php

namespace App\Http\Controllers\Admin;

use App\Components\DXUtil;
use App\Enums\SmsTempEnum;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Jobs\ProcessPodcast;
use App\Jobs\SendChangeOrderMessage;
use App\Jobs\SendSmsMessageJob;
use App\Models\AppMiniPlate;
use App\Models\AppTypeModel;
use App\Models\AuthenticLog;
use App\Models\Category;
use App\Models\Config;
use App\Models\Goods;
use App\Models\GoodsDepict;
use App\Models\GoodsSetmeal;
use App\Models\GoodsSpec;
use App\Models\MemberLegal;
use App\Models\MemberOther;
use App\Models\MemberQnRisk;
use App\Models\OrderGoods;
use App\Models\OrderRadarBoolea;
use App\Models\OrderRate;
use App\Models\OrderRemark;
use App\Models\OrderReturn;
use App\Models\OrderRiskBoolea;
use App\Models\OtherOrder;
use App\Models\OtherOrderAllocate;
use App\Models\OtherWithholdLog;
use App\Models\RiskCredit;
use App\Models\SaleUser;
use App\Models\ShopSms;
use App\Models\ShopUser;
use App\Models\Order;
use App\Models\OrderLease;
use App\Models\Complain;
use App\Models\SmsRecord;
use App\Models\SmsTemplate;
use App\Models\Source;

use App\Services\AlipayMiniAppService;
use App\Services\AlipayService;
use App\Services\AntchainAtoServicejuzu;
use App\Services\AntchainService;
use App\Services\AppTypeService;
use App\Services\BaofupayService;
use App\Services\BaofuWithdrawPayService;
use App\Services\BuErService;
use App\Services\ChargeService;
use App\Services\CommonService;
use App\Services\CreditCallService;
use App\Services\EducationService;
use App\Services\EsignService;
use App\Services\EsignV3Service;
use App\Services\GoodsService;
use App\Services\HuifupayService;
use App\Services\InteractiveRiskQueryService;
use App\Services\NotarizeService;
use App\Services\RedisService;
use App\Services\RelationVerifyService;
use App\Services\RiskDlzwService;
use App\Services\SafeService;
use App\Services\SmsService;
use App\Services\StrategyService;
use App\Services\RadarService;
use App\Services\RiskService;
use App\Services\CreditService;
use App\Services\OrderService;
use App\Services\XinyanService;
use Illuminate\Http\Request;
use App\Models\OrderCredit;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Nette\Utils\Image;
use function Psy\debug;
use Illuminate\Support\Facades\DB;
use App\Services\AlipayMessageService;
use App\Services\AliyunSmsService;
use App\Services\AntchainPlusService;
use App\Services\YpcreditService;
use App\Services\BairaongService;
use App\Services\WechatService;
use App\Services\AlipayRiskService;
use App\Services\AntchainAtoService;
use App\Services\AlipayRealpersonService;


class TestController extends Controller
{
    public function iphoneCountList(Request $request){

        if(strtotime($request['start_time'])>strtotime($request['end_time'])){
            exit('开始时间不能大于结束时间');
        }
        if(!$request['start_time']||!$request['end_time']){
            exit('请选择时间');
        }

        $interval=floor((strtotime($request['end_time'])-strtotime($request['start_time']))/86400);
        for($i=0;$i<=$interval;$i++){
                $count=Order::from('sp_order_2 as o')
                ->where('o.phone_brand','like','%'.'iPhone'.'%')
                ->where('m.cert_name','<>','0')
                ->where('o.create_time','<',strtotime($request['start_time'])+($i+1)*86400)
                ->where('o.create_time','>',strtotime($request['start_time'])+$i*86400)
                ->where('o.status','<',10)
                ->where('m.is_use',0)
                ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
                ->distinct('m.mobile')
                ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.phone_brand','o.trade_no','o.status',
                    'o.id','o.begin_time','o.end_time','o.create_time')
                ->orderBy('m.id','desc')
                ->count();
                echo '时间'.date('Y-m-d',strtotime($request['start_time'])+$i*86400).'：'.$count.'<br/>';
          }
        exit();
    }
    //苹果设备
    public function iphoneList(Request $request){

//        if(strtotime($request['start_time'])>strtotime($request['end_time'])){
//            exit('开始时间不能大于结束时间');
//        }
//        if(!$request['start_time']||!$request['end_time']){
//            exit('请选择时间');
//        }
        set_time_limit(0);
        $user= Order::from('sp_member_2 as m')
            ->where('m.equipment','like','%HONOR%')//iPhone,HUAWEI,HONOR
            ->where('m.mobile','<>','0')
//            ->where('m.create_time','<',strtotime($request['end_time'])+86399)
//            ->where('m.create_time','>',strtotime($request['start_time']))
            ->groupBy('m.mobile')
            ->select('m.mobile','m.cert_name','m.cert_no','m.equipment','m.create_time','m.id')
            ->orderBy('m.id','desc')
            ->get()->toArray();
        $num = 0;
        $mobile=[];
        foreach ($user as $key=>$value) {
            if(Order::where('uid',$value['id'])->where('status','>=',10)->count()>0){
                continue;
            }
            $dataInfo[$key][] = $value['equipment'];
            $dataInfo[$key][] = $value['mobile'];
            $mobile[]=$value['mobile'];
            $dataInfo[$key][] = $value['cert_name'];
            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//           MemberOther::where('cert_no',$value['cert_no'])->update(['is_use'=>1]);
        }

        $dataInfoa=[];
        $user= Order::from('sp_order_2 as o')
            ->where('o.phone_brand','like','%HONOR%')
//            ->where('m.cert_name','<>','0')
//            ->where('o.create_time','<',strtotime($request['end_time'])+86399)
//            ->where('o.create_time','>',strtotime($request['start_time']))
            ->where('o.status','<',10)
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->groupBy('m.mobile')
            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.phone_brand','o.trade_no','o.status',
                'o.id','o.begin_time','o.end_time','o.create_time')
            ->orderBy('m.id','desc')
            ->get()->toArray();
        //dd(count($user));
        foreach ($user as $key=>$value) {
            if(in_array($value['mobile'],$mobile)){
                continue;
            }
            $dataInfoa[$key][] = $value['phone_brand'];
            $dataInfoa[$key][] = $value['mobile'];
            $dataInfoa[$key][] = $value['cert_name'];
            $dataInfoa[$key][] = date('Y-m-d H:i:s',$value['create_time']);
        }

        $dataInfo=array_merge($dataInfo,$dataInfoa);
//        dd(count($dataInfo));
        $headList = [
            '设备型号',
            '手机号码',
            '姓名',
            '下单时间',
        ];

        $title = "HUAWEI设备数据".$request['start_time'].'至'.$request['end_time'];

        //调用上面的方法
        return  csvExporta($dataInfo, $headList, $title);
        exit();
    }
    public function zlbtest(Request $request){


        set_time_limit(0);
        // 设置日志文件的路径
        $logFilePath = '/www/wwwroot/www.doulaizu.com/exported_loga.log';

// 使用file()函数读取文件到数组中
        $logLines = file($logFilePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
//var_dump($logLines);
// 处理数组中的每一行
        $logEntries = array();
        foreach ($logLines as $line) {
            // 根据日志格式解析每一行，这里只是简单地分割成数组
            $logEntry = explode(' ', $line);
            $logEntries[] = $logEntry;
        }
        foreach ($logEntries as $ra){

//            dd(str_replace('[', '', $ra[3]));
            $dateString=str_replace('[', '', $ra[3]).' +0800';
//            $timezone = new DateTimeZone('Asia/Shanghai'); // 设置正确的时区
            $dateTime = \DateTime::createFromFormat('d/M/Y:H:i:s P', $dateString);
            $time = $dateTime->getTimestamp();
            if($ra[6]=='/extenda.html'){
                $sale_user_id='012418205971';
            }
            if($ra[6]=='/extendb.html'){
                $sale_user_id='012610455071';
            }
            if($ra[6]=='/extendc.html'){
                $sale_user_id='012610463751';
            }
            if($ra[6]=='/extend.html'){
                $sale_user_id='012418193027';
            }
            $arr=['sale_user_id'=>$sale_user_id??0,'ip'=>$ra[0],'create_time'=>$time];
            Db::table('sp_extension_statistics')->insert($arr);
        }

        return $logEntries;
//
//        $result=WechatService::get_order_list();
//        $result=json_decode($result['data'],true);
//        if($result['order_list']){
//            foreach ($result['order_list'] as $ra){
//
//                $where=[];
//                $where[] =['ol.trade_no', $ra['transaction_id']];
//                $where[] =['m.openId', '<>',''];
//                $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//                    ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//                    ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//                    ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//                    ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//                    ->select(
//                        'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
//                        'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
//                        , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//                        , 'm.mobile',
//                    )->where($where)->orderBy('id','asc')->first();
//
//                if($order&&$order['openId']&&$order['which_period']>1){
//                    $order['out_order_no']=$ra['transaction_id'];
//                    return  WechatService::upload_shipping_info_lease($order,$order['which_period']);
//                }
//            }
//        }
//
//        return 0;

//        $count= Order::from('sp_order_2 as o')
//            ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751'])
//            ->where('o.seller_id','<>','202309081070080001')
//            ->count();
//        return $count;
               //导出核对数据
       $usera= Order::from('sp_order_2 as o')
       ->whereIn('o.status',[60])
       ->leftjoin('sp_member_2 as m','m.id','o.uid')
       ->leftjoin('sp_order_lease_2 as ol','ol.order_id','o.id')
       ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status','o.create_time')
       ->distinct('m.id')
       ->limit(10)
       ->orderBy('ol.pay_time','desc')
       ->get()->toArray();

        $userb= Order::from('sp_order_2 as o')
            ->where('o.status',39)
            ->leftjoin('sp_member_2 as m','m.id','o.uid')
            ->leftjoin('sp_order_lease_2 as ol','ol.order_id','o.id')
            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status','o.create_time')
            ->distinct('m.id')
            ->limit(10)
            ->get()->toArray();

        $user=array_merge($usera,$userb);

//        shuffle($user);

        $num = 0;
        $dataInfo=[];
        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = $key;
            $dataInfo[$key][] = " ".$value['trade_no']."\t";
            $dataInfo[$key][] = $value['cert_name'];
            // 日期
            $dataInfo[$key][] =" ".$value['cert_no']."\t";
            // 序号
            $dataInfo[$key][] = " ".$value['mobile']."\t";
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] =hash("sha256", $value['cert_no']);
//            $dataInfo[$key][] =date('Y-m-d',$value['create_time']);
        }

        $headList = [
            '序号',
            '订单号',
            '姓名',
            '身份证',
            '手机号',
            '状态',
//            'sha256加密后的身份证号码',
//            '下单时间',
        ];

        $title = "导出cvs数据";

        //调用上面的方法
        return csvExporta($dataInfo, $headList, $title);

//       exit();
//
////dd($order);
//       foreach ($order as $ra) {
//           $object = 'https://img.qianbaozuji.com/' . $ra['pact_url'];
//           var_dump($object);
//           $file = file_get_contents($object);
//           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/concact/' . $ra['cert_name'].'.pdf';
//           //               dd($path);
//           $res = file_put_contents($path, $file);
////        dd($res);
//       }
//exit();

        //推单
//        $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->select(
//                'o.face_flow_id', 'o.id','o.trade_no','o.location','o.status',
//                'o.uid',
//            )->where('m.contract_no','<>','')->where('o.status',4)->where('o.username','admin')->where('o.face_flow_id','<>','')->orderBy('id','desc')->get();
//
//        $order=$order->toArray();
//        foreach ($order as $ra){
//            //推单
//
//            $contextId = $ra['uid'];
//            $log['order_id']=$ra['id'];
//            if($log['order_id']){
//                $ordercount=Order::from('sp_order_2 as o')
//                    ->where('o.uid',$contextId)
//                    ->where('u.contract_no','<>','')
//                    ->leftjoin('sp_member_2 as u','o.uid','u.id')
//                    ->count();
//                if($ordercount==1){
//
//                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                    $otherMember = obToArray($otherMember);
//
//                    if(empty($otherMember)){
//                        OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
//                        $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                        $otherMember = obToArray($otherMember);
//                    }
//
//                    if($ordercount&&$otherMember){
//                        if($otherMember['limit']){
//                            $order_limit_count=OtherOrder::where('member_id',$otherMember['member_id'])->whereDate('created_at', date('Y-m-d'))->count();
//                            if($order_limit_count>=$otherMember['limit']){
//                                $otherMember=OtherOrderAllocate::whereRaw('limit = 0')->first();
//                            }
//                        }
//
//                        OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
//                        $isSendOther=$otherMember['member_id']?1:0;
//                    }else{
//                        return $request_data;
//                    }
//
//                    $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');
//
//
//                    $order_data= Order::from('sp_order_2 as o')->where('o.id',$log['order_id'])->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->first();
//                    $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
//                    $order_lease_data=obToArray($order_lease_data);
//                    $member = MemberOther::where('id',$contextId)->first();
//                    $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
//                    $goods = Goods::GoodsInfo($orderGoods['goods_id']);
//                    $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
//                    $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
//                    $order_goods_data['goods']  = $goods;
//                    $order_goods_data['goods_setmeal']  = $setmeal;
//                    $order_goods_data['goods_spec'] =$spec;
//
//
//                    if($isSendOther){
//                        $order_data['order_form']='wechat';
//                        $add_remark = [
//                            'uid'=>'23',
//                            'username'=>'同步',
//                            'create_time'=>time(),
//                            'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
//                            'order_id'=>$log['order_id']
//                        ];
//                        OrderRemark::insert($add_remark);
//                        Order::where('id',$log['order_id'])->update(['username'=>'admin']);
//                    }
//
//                    $OtherOrder=[
//                        'order_data'=>json_encode($order_data),
//                        'order_lease_data'=>json_encode($order_lease_data),
//                        'goods_data'=>json_encode($order_goods_data),
//                        'member_data'=>json_encode($member->toArray()),
//                        'remark_data'=>'[]',
//                        'member_id'=>$otherMember['member_id'],
//                        'order_id'=>$log['order_id'],
//                        'status'=>1,
//                        'is_allocate'=>1,
//                    ];
//
//
//                    OtherOrder::create($OtherOrder);
////                    dd($log['order_id']);
//                }
//            }
//        }
//        return $order;
return SafeService::expressCreate();


//        $res=AntchainPlusService::uploadPerformance('SANDBOX231011000000502901',2,97485,'123456');
//        return $res;
//        $res=AntchainPlusService::updatePromiseRepayment('SANDBOX231011000000504586',2);
//        return $res;
//        $res= AntchainPlusService::registerBclMerchant();
//        return $res;
//        $res= AntchainPlusService::queryOrder('PROD231017000000910005');
//        return $res;

    }
    public function exportNoPay(){


//       $res=MemberOther::whereIn('cert_no',["330683198612110013","320922199702122014","320922199702122014","411528199912182217","445281200005084357","371302199304070812","152324199506301111","152324199506301111","510922198402083691","510922198402083691","510922198402083691","410726200111130057","410726200111130057","352230198802170616","352230198802170616","352230198802170616","352230198802170616","0","500236199907232659","500236199907232659","370783199602153316","370783199602153316","370783199602153316","370783199602153316","321111199101221621","321111199101221621","321111199101221621","513001198702010218","513001198702010218","513001198702010218","340404199802040810","450328200110132411","450328200110132411","412829198904113229","350521198511118525","350521198511118525","350521198511118525","0","320830199811103618","320830199811103618","440823199911164614","440823199911164614","440823199911164614","420684199811225078","420684199811225078","420684199811225078","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","132801198903152214","132801198903152214","510802198602191717","342401199309272274","533422199101271510","342401199309272274","342401199309272274","220602199502030937","37292219890201521X","37292219890201521X","320106198805103221","320106198805103221","320106198805103221","320106198805103221","320106198805103221","37132619900710006X","37292219890201521X","220204198810110011","220204198810110011","220204198810110011","220204198810110011","220204198810110011","372928198812210212","372928198812210212","420703199805076392","420703199805076392","131121199911251416","131121199911251416","350583199011053116","350583199011053116","0","0","36078219920301381X","36078219920301381X","36078219920301381X","36078219920301381X","370725199712225276","433125199109010031","210202199209245927","210202199209245927","210202199209245927","0","441283200111304594","441283200111304594","441283200111304594","441283200111304594","422823199003264458","420204199806096511","210882199412263914","210882199412263914","210882199412263914","210882199412263914","210882199412263914","210882199412263914","230227198709012851","532325199207241515","422823199003264458","422823199003264458","422823199003264458","422823199003264458","422823199003264458","422823199003264458","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","130529198605010021","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","330681199601057087","330681199601057087","330681199601057087","50010919950106251X","50010919950106251X","50010919950106251X","342425199805020528","340301199712090019","430124199709294745","430124199709294745","430124199709294745","430124199709294745","460033199502243883","460033199502243883","460033199502243883","232303198909251028","232303198909251028","232303198909251028","232303198909251028","232303198909251028","370303199010293936","370303199010293936","142723198912070215","330624199905115330","500102199406217996","513721199305080050","220322199810250949","220322199810250949","230123198506151113","230123198506151113","230123198506151113","370523199009231013","370523199009231013","370523199009231013","370523199009231013","320981199810130476","320981199810130476","341226198801043837","210623198401063495","210623198401063495","210623198401063495","340301199712090019","340301199712090019","610123199009277271","411503199611181029","411503199611181029","230604199211165123","331023200305143175","330183199510213019","330183199510213019","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","411282199803196515","510922199001014227","231182200101165622","522426199109273230","511621199310081042","430723199611287850","445122198912165091","412825199611036433","440508198704122943","230230199711182123","230230199711182123","331023200305143175","331023200305143175","331023200305143175","331023200305143175","131123200511260039","131123200511260039","131123200511260039","131123200511260039","131123200511260039","330227198201046376","612321199101240527","350524199902178019","130503199507270613","510183199502191618","23230219980806001X","510922199910161136","43052719931008662X","43052719931008662X","43052719931008662X","43052719931008662X","43052719931008662X","0","0","412724198904070057","410927200102284027","411503199611181029","411503199611181029","513901199801100028","232324198803055119","220103198610064530","320882199402031613","411327198810101138","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","441381200108281814","230206199510190717","320882199212212659","321322200212103818","430581199604067289","430581199604067289","430581199604067289","230123199901222254","230123199901222254","230123199901222254","320281199002042277","372328198803140029","210682198601121063","210682198601121063","440681198702135428","441821198609280220","511622198704102274","410724199704243016","130322199008272014","130223199808314316","61242319980820101X","342523199505053742","610115199502115516","371426199811300017","371426199811300017","371426199811300017","230206199510190717","230206199510190717","230206199510190717","230206199510190717","420683199411162518","420683199411162518","340221199412202867","340221199412202867","340221199412202867","411323198206172612","411421200201206812","210521199707260033","210521199707260033","441821198609280220","441821198609280220","0","452622199708033316","131102199410180438","610422199911201415","350881199303100918","350881199303100918","410926199810080031","410926199810080031","410926199810080031","410926199810080031","220204199301310925","230622199303260868","230622199303260868","230622199303260868","230622199303260868","220204199301310925","220204199301310925","452231199710252010","430181199908140068","320923199606282428","51322719980814001X","320682198310306127","320682198310306127","320682198310306127","320682198310306127","320682198310306127","452623198309054234","452623198309054234","130481199605290478","130481199605290478","130481199605290478","320682199410028456","320682199410028456","411122199510157545","411122199510157545","411122199510157545","0","130821198701037975","130821198701037975","130821198701037975","411327198506190623","411327198506190623","411327198506190623","411327198506190623","511303199109213761","610329199807211217","220204198810110011","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","445102199304151920","445102199304151920","412702198804165050","412702198804165050","510781199710263559","510781199710263559","510781199710263559","340503199309190216","430421199007286035","430421199007286035","360622200107093227","360622200107093227","360622200107093227","360622200107093227","360622200107093227","360622200107093227","412724199104290355","412724199104290355","412724199104290355","412724199104290355","410403199201115524","450204198911201417","450204198911201417","640324200101053295","640324200101053295","640324200101053295","0","0","410702199703080018","340503199309190216","340503199309190216","440883198611083515","612323199610082910","110224198802253426","230321199411245937","230321199411245937","230321199411245937","320323199610110415","513223199807021435","410711198803211013","410711198803211013","370612199509061520","370612199509061520","152104199504143512","152104199504143512","429005200301300045","500102198712144778","500102198712144778","511381199505283779","511381199505283779","511381199505283779","511381199505283779","32012119940926251X","32012119940926251X","320283199105101367","320283199105101367","320283199105101367","131126199301111813","131126199301111813","131126199301111813","510602199504271514","230503198910140818","230503198910140818","433122198606042524","433122198606042524","130182199205174849","130182199205174849","130182199205174849","130182199205174849","42010419831228271X","42010419831228271X","42010419831228271X","310115199906042228","310115199906042228","310115199906042228","310115199906042228","310115199906042228","310115199906042228","210404199308204323","210404199308204323","210404199308204323","370686199406096514","370686199406096514","370686199406096514","370686199406096514","370686199406096514","0","320114199705152717","320114199705152717","370781199309094828","370781199309094828","370781199309094828","330781199510155920","330781199510155920","330781199510155920","52262219841111002X","0","500235199711080490","500235199711080490","511623199709175393","511623199709175393","110115199802152636","110115199802152636","110115199802152636","110115199802152636","32068419940518617X","32068419940518617X","32068419940518617X","612323199610082910","612323199610082910","612323199610082910","612323199610082910","32058619991113453X","32058619991113453X","612323199610082910","513029199708140065","513029199708140065","37148219950805001X","352203198912250087","362322199808160103","210102198202082213","413026199611166012","230105199606013422","370124199504233010","320981199402082217","320981199402082217","37148219950805001X","37148219950805001X","37148219950805001X","36011120000918652X","36011120000918652X","36011120000918652X","321023200012110810","321023200012110810","321023200012110810","532901198610250929","532901198610250929","210213199703170018","210213199703170018","210213199703170018","320323200203312015","320323200203312015","420582199304080080","330382198604090312","511025199112123443","511025199112123443","510902198508078326","152631198410052718","152631198410052718","152631198410052718","152631198410052718","152631198410052718","320323199308167920","511521199805087942","511521199805087942","511521199805087942","511521199805087942","511521199805087942","510106199003285115","510106199003285115","510106199003285115","612526199311138371","610422199509251772","610422199509251772","610422199509251772","610422199509251772","610422199509251772","21102119860705002X","21102119860705002X","330781199512025919","330781199512025919","330781199512025919","21028120000606641X","420621200008167710","420621200008167710","420621200008167710","532722199510310221","532722199510310221","532722199510310221","532722199510310221","0","440582199710292138","440582199710292138","130632199909087229","130632199909087229","130632199909087229","130632199909087229","130632199909087229","511623199607230021","370684198607257356","370684198607257356","511526199610125533","511526199610125533","511526199610125533","510503198511114054","510503198511114054","510503198511114054","510503198511114054","51052119971108343X","51052119971108343X","340825199907133718","0","0","0","210221199209156915","43098119920516821X","43098119920516821X","130281199607260722","142402198912156627","142402198912156627","142402198912156627","612525199403203656","371426200006284814","452702199602214573","452702199602214573","0","120113200101290010","120113200101290010","120113200101290010","220112200111261421","220112200111261421","130206199009050338","130206199009050338","130206199009050338","330483199304190051","532923198904200028","450225200010162213","140702199106267081","510602199504271514","510602199504271514","420525199403182819","321102198810031571","321102198810031571","321102198810031571","620103199808233028"])->where('cert_no','<>',0)->pluck('cert_no');
//        return $res;
//        $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->select(
//                'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
//                'ol.paid_rent','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
//                , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//                , 'm.mobile','m.cert_name','ol.pay_time',
//            )->where('ol.pay_time','>','1698768000')->where('ol.pay_time','<','1701360000')->where('o.seller_id','=','1685775283')->orderBy('pay_time','asc')->get()->toArray();
//
//        foreach ($order as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['pay_time']);
//            // 序号
//            $dataInfo[$key][] = $value['cert_name'];
//            // 日期
//            $dataInfo[$key][] =' '.$value['trade_no'].'/t';
//            // 用户名
//            $dataInfo[$key][] = $value['paid_rent'];
//        }
//
//        $headList = [
//            '还款时间',
//            '姓名',
//            '订单号',
//            '金额',
//        ];
//
//        $title = "小白十一月还款";
//
//        //调用上面的方法
//        return  csvExport($dataInfo, $headList, $title);
//        exit();

        $user= Order::from('sp_order_2 as o')
            ->where('o.status', '>','4')
            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->distinct('m.id')
            ->select('m.mobile','m.cert_name','o.trade_no','o.month_total','s.shopname','o.is_lock',
                'og.acquisition_price','og.pact_type','og.setmeal_price','o.status','o.id','o.begin_time','o.reduced_price','m.contract_no','o.order_from','m.openId','o.sale_user_id')
            ->get()->toArray();

        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = $value['begin_time'];
            // 序号
            $dataInfo[$key][] = $value['cert_name'];
            // 日期
            $dataInfo[$key][] =' '.$value['trade_no'].'/t';
            // 用户名
            $dataInfo[$key][] = $value['shopname'];
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
            $dataInfo[$key][] = OrderLease::where('order_id',$value['id'])->sum('rent');
            $rent=OrderLease::where('order_id',$value['id'])->where('status',1)->sum('rent');
            $dataInfo[$key][] = bcadd($rent,$value['reduced_price'],2);
            $dataInfo[$key][] = $value['acquisition_price'];
            $dataInfo[$key][] = $value['month_total'];
            $dataInfo[$key][] = $value['is_lock']?'有':'无';

            $source = Source::where(['source_code' => $value['order_from'], 'status' => Source::SOURCE_STATUS_ENABLE])->value('source_name');
            $shopRate = OrderRate::where(['order_id' => $value['id']])->value('shop_rate');
            if($value['order_from']=='saleOnline'&&$value['openId']){
                $source=$source.'-微信';
            }
            if($value['order_from']=='saleOnline'&&empty($value['openId'])){
                $source=$source.'-支付宝';
            }
            if($value['contract_no']){
                $source=$source.'-W';
            }
            $shopRate = !empty($shopRate) ? "(" . $shopRate . "%)" : '';
            $source=$source . $shopRate;
            $channel_name=SaleUser::where('sale_user_id',$value['sale_user_id'])->value('channel_name');
            if($channel_name){
                $source=$source.'-'.$channel_name;
            }
            $dataInfo[$key][] = $source;
            if($value['pact_type']=='1'){
                $dataInfo[$key][] = $value['setmeal_price']>0?$value['setmeal_price']:0;
            }else{
                $dataInfo[$key][] = '无';
            }
        }


        $headList = [
            '租赁时间',
            '姓名',
            '订单号',
            '供应商',
            '状态',
            '应还',
            '已还款金额',
            '采购价格',
            '总期数',
            '是否有锁',
            '推广平台',
            '买断金',
        ];

        $title = "还款数据";

        //调用上面的方法
        return  csvExport($dataInfo, $headList, $title);
        exit();
    }

    /**
     * 推单推单
     * @param Request $request
     * @return mixed|void
     */
    public function pushOrder(Request $request)
    {

        $uids=Order::from('sp_order_2 as o')
            ->where('o.seller_id','202409107012090001')
            ->where('o.create_time','>','1726848000')
            ->leftjoin('sp_member_2 as u','o.uid','u.id')
            ->pluck('uid');
        $order= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m','m.id','o.uid')
            ->whereNotIn('o.uid',$uids)
            ->where('m.cert_no','<>','')
            ->where('m.cert_no','<>','0')
            ->where('m.cert_name','<>','')
            ->where('m.cert_name','<>','0')
            ->where('o.sale_user_id','091114064339')
            ->where('o.seller_id','1704471738')
            ->where('o.status',4)
            ->orderBy('o.id','desc')
            ->groupBy('o.uid')
            ->select('o.uid','m.cert_name','m.mobile','o.id','o.trade_no')->get()->toArray();
        $i=0;
        foreach ($order as $ra){
            $contextId = $ra['uid'];
            $log['order_id']=$ra['id'];
            if($log['order_id']){

                $otherorderData=OtherOrder::where('trade_no',$ra['trade_no'])->value('id');
                $orderremark=OrderRemark::getRemark($ra['id']);
                if($otherorderData||$orderremark){
                    continue;
                }

                $ordercount=Order::from('sp_order_2 as o')
                    ->where('o.uid',$contextId)
                    ->where('o.seller_id','202409107012090001')
                    ->where('o.status','<>',2)
                    ->leftjoin('sp_member_2 as u','o.uid','u.id')
                    ->count();

                $otherMember=OtherOrderAllocate::where('member_id','202409107012090001')->first();
                $otherMember = obToArray($otherMember);

                if(empty($otherMember)){
                    OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
                    $otherMember = obToArray($otherMember);
                }


                if($ordercount<1){
                    if($otherMember){
                        OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                        $isSendOther=$otherMember['member_id']?1:0;
                    }else{
                        return '';
                    }
                    $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');
                    $order_data= Order::from('sp_order_2 as o')->where('o.id',$log['order_id'])->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->first();
                    $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
                    $order_lease_data=obToArray($order_lease_data);
                    $member = MemberOther::where('id',$contextId)->first();
                    $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
                    $goods = Goods::GoodsInfo($orderGoods['goods_id']);
                    $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
                    $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
                    $order_goods_data['goods']  = $goods;
                    $order_goods_data['goods_setmeal']  = $setmeal;
                    $order_goods_data['goods_spec'] =$spec;


                    if($isSendOther){
                        $order_data['order_from']='alipay';
                        $add_remark = [
                            'uid'=>'23',
                            'username'=>'同步',
                            'create_time'=>time(),
                            'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
                            'order_id'=>$log['order_id']
                        ];
                        OrderRemark::insert($add_remark);
                        Order::where('id',$log['order_id'])->update(['username'=>'admin','seller_id'=>$otherMember['member_id']]);
                    }

                    $OtherOrder=[
                        'order_data'=>json_encode($order_data),
                        'trade_no'=>$order_data['trade_no'],
                        'order_lease_data'=>json_encode($order_lease_data),
                        'goods_data'=>json_encode($order_goods_data),
                        'member_data'=>json_encode($member->toArray()),
                        'remark_data'=>'[]',
                        'member_id'=>$otherMember['member_id'],
                        'order_id'=>$log['order_id'],
                        'status'=>1,
                        'from'=>1,
                        'is_allocate'=>1,
                    ];


                    OtherOrder::create($OtherOrder);
                    var_dump($order_data);
//                    dd($log['order_id']);
                }
            }
        }
return true;
//        $uids=Order::from('sp_order_2 as o')
//            ->where('o.seller_id','202309081070080001')
//            ->where('o.create_time','>','1726848000')
//            ->leftjoin('sp_member_2 as u','o.uid','u.id')
//            ->pluck('uid');
        $order= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->whereNotIn('o.uid',$uids)
//            ->where('m.cert_no','<>','')
//            ->where('m.cert_no','<>','0')
//            ->where('m.cert_name','<>','')
//            ->where('m.cert_name','<>','0')
//            ->where('o.create_time','>','1726848000')
//            ->whereNull('o.sale_user_id')
//            ->where('o.seller_id','1678175782')
//            ->where('o.status',4)
                ->whereIn('o.trade_no',['20241012173632383667','20241012173410459522','20241012173209713123','20241012172947127583',
                '20241012172607502658','20241012172715584946','20241012172713433195','20241012173907277112','20241012174110845342','20241012174102629035'])
            ->orderBy('o.id','desc')
            ->groupBy('o.uid')
//            ->limit(5)
            ->select('o.uid','m.cert_name','m.mobile','o.id','o.trade_no')->get()->toArray();
//        return $order;
        foreach ($order as $ra){
            $contextId = $ra['uid'];
            $log['order_id']=$ra['id'];
            if($log['order_id']){

                $otherorderData=OtherOrder::where('trade_no',$ra['trade_no'])->value('id');
                if($otherorderData){
                   continue;
                }
                $ordercount=Order::from('sp_order_2 as o')
                    ->where('o.uid',$contextId)
                    ->where('o.seller_id',$otherMember['member_id'])
                    ->where('o.id','<>',$ra['id'])
                    ->where('o.create_time','>',strtotime('-30 day'))
                    ->where('o.status','<>',2)
                    ->leftjoin('sp_member_2 as u','o.uid','u.id')
                    ->count();

                $otherMember=OtherOrderAllocate::where('member_id','202309081070080001')->first();
                $otherMember = obToArray($otherMember);

                if(empty($otherMember)){
                    OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
                    $otherMember = obToArray($otherMember);
                }


                if($ordercount<1){
                    if($otherMember){
                        OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                        $isSendOther=$otherMember['member_id']?1:0;
                    }else{
                        return '';
                    }
                    $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');
                    $order_data= Order::from('sp_order_2 as o')->where('o.id',$log['order_id'])->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->first();
                    $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
                    $order_lease_data=obToArray($order_lease_data);
                    $member = MemberOther::where('id',$contextId)->first();
                    $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
                    $goods = Goods::GoodsInfo($orderGoods['goods_id']);
                    $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
                    $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
                    $order_goods_data['goods']  = $goods;
                    $order_goods_data['goods_setmeal']  = $setmeal;
                    $order_goods_data['goods_spec'] =$spec;


                    if($isSendOther){
                        $order_data['order_from']='alipay';
                        $add_remark = [
                            'uid'=>'23',
                            'username'=>'同步',
                            'create_time'=>time(),
                            'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
                            'order_id'=>$log['order_id']
                        ];
                        OrderRemark::insert($add_remark);
                        Order::where('id',$log['order_id'])->update(['username'=>'admin','seller_id'=>$otherMember['member_id']]);
                    }

                    $OtherOrder=[
                        'order_data'=>json_encode($order_data),
                        'trade_no'=>$order_data['trade_no'],
                        'order_lease_data'=>json_encode($order_lease_data),
                        'goods_data'=>json_encode($order_goods_data),
                        'member_data'=>json_encode($member->toArray()),
                        'remark_data'=>'[]',
                        'member_id'=>$otherMember['member_id'],
                        'order_id'=>$log['order_id'],
                        'status'=>1,
                        'from'=>1,
                        'is_allocate'=>1,
                    ];


                    OtherOrder::create($OtherOrder);
                    var_dump($ra['id']);
//                    dd($log['order_id']);
                }
            }
        }
    }

    //订单的导出
    public function exportOrders()
    {
     return   $user= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->where('o.seller_id','202309081070080001')
            ->where('o.sale_user_id','091114064339')
            ->distinct('o.uid')
            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.create_time','o.status','o.id','o.rent_total','o.uid','o.sale_user_id')
            ->pluck('m.cert_no');

            $user= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
            ->whereIn('m.cert_no',$user)
            ->where('o.status','>','10')
            ->orderBy('o.id','asc')
            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time','o.status',
                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
            ->get()->toArray();
        $user=obToArray($user);
        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = date('Y-m-d',$value['create_time']);
            $dataInfo[$key][] = "\t".$value['cert_no'];
            $dataInfo[$key][] = $value['cert_name'];
            $dataInfo[$key][] = $value['mobile'];
            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
            $dataInfo[$key][] =SaleUser::where('sale_user_id',$value['sale_user_id'])->value('channel_name');
        }
        $headList = [
            '创建时间',
            '身份证号码',
            '姓名',
            '电话',
            '商品名称',
            '订单金额',
            '状态',
            '渠道'
        ];
        $title = "用户订单";
        //调用上面的方法
        return  csvExporta($dataInfo, $headList, $title);

//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('o.sale_user_id','<>','')
//            ->orderBy('o.id','asc')
//            ->groupBy('o.uid')
//            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time','o.status',
//                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            if($value['sale_user_id']=='012418193027'){
//                $dataInfo[$key][] ='f1';
//            }else if($value['sale_user_id']=='012418205971'){
//                $dataInfo[$key][] ='f2';
//            }else if($value['sale_user_id']=='012610455071'){
//                $dataInfo[$key][] ='f3';
//            }else if($value['sale_user_id']=='012610463751'){
//                $dataInfo[$key][] ='f4';
//            }else if($value['sale_user_id']=='042419335455'){
//                $dataInfo[$key][] ='f5';
//            }
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '商品名称',
//            '订单金额',
//            '状态',
//            '渠道'
//        ];
//        $title = "用户订单";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
//
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->where('o.status',39)
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->select('m.mobile','m.cert_name','m.cert_no','m.level_performance','o.id as order_id','o.id as orderId','o.uid','o.seller_id','o.status')
//            ->limit(100)
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//
//            $resa=OrderRadarBoolea::getRiskHistoryData($value['cert_no']);
//            $res=OrderRadarBoolea::getRiskData($value['cert_no']);
//            $radara=json_decode($resa['result'],true)['resp_data']['behavior_report_detail'];
//            $dataInfo[$key][] = "\t".$radara['B22170045'].'/'.$radara['B22170035'];//历史雷达近一个月
//            $radar=json_decode($res['result'],true)['resp_data']['behavior_report_detail'];
//            $dataInfo[$key][] = "\t".$radar['B22170045'].'/'.$radar['B22170035'];//雷达近一个月
//            $resa=OrderRiskBoolea::getRiskHistoryData($value['orderId']);
//            $res=OrderRiskBoolea::getRiskNewsData($value['orderId']);
//
//            $riska=json_decode($resa['result'],true)['resp_data']['personal_loan_h'];
//            $dataInfo[$key][] = "\t".$riska['repay_succ1'].'/'.$riska['repay_fail1'];//历史布尔近一个月
//
//            $risk=json_decode($res['result'],true)['resp_data']['personal_loan_h'];
//            $dataInfo[$key][] = "\t".$risk['repay_succ1'].'/'.$risk['repay_fail1'];//布尔近一个月
//
//            $dataInfo[$key][] = "\t".$radara['B22170046'].'/'.$radara['B22170036'];//历史雷达近一个月3
//            $dataInfo[$key][] = "\t".$radar['B22170046'].'/'.$radar['B22170036'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ3'].'/'.$riska['repay_fail3'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ3'].'/'.$risk['repay_fail3'];//布尔近一个月
//
//            $dataInfo[$key][] = "\t".$radara['B22170047'].'/'.$radara['B22170037'];//历史雷达近一个月6
//            $dataInfo[$key][] = "\t".$radar['B22170047'].'/'.$radar['B22170037'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ6'].'/'.$riska['repay_fail6'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ6'].'/'.$risk['repay_fail6'];//布尔近一个月
//
//
//            $dataInfo[$key][] = "\t".$radara['B22170048'].'/'.$radara['B22170038'];//历史雷达近一个月12
//            $dataInfo[$key][] = "\t".$radar['B22170048'].'/'.$radar['B22170038'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ12'].'/'.$riska['repay_fail12'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ12'].'/'.$risk['repay_fail12'];//布尔近一个月
//
//
//            $dataInfo[$key][] = "\t".$radara['B22170049'].'/'.$radara['B22170039'];//历史雷达近一个月24
//            $dataInfo[$key][] = "\t".$radar['B22170049'].'/'.$radar['B22170039'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ24'].'/'.$riska['repay_fail24'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ24'].'/'.$risk['repay_fail24'];//布尔近一个月
//
//
//        }
//        $headList = [
//            '姓名',
//            '电话',
//            '身份证',
//            '历史数据雷达近一个月',
//            '雷达近一个月',
//            '历史数据布尔近一个月',
//            '布尔近一个月',
//            '历史数据雷达近3个月',
//            '雷达近3个月',
//            '历史数据布尔近3个月',
//            '布尔近3个月',
//            '历史数据雷达近6个月',
//            '雷达近6个月',
//            '历史数据布尔近6个月',
//            '布尔近6个月',
//            '历史数据雷达近12个月',
//            '雷达近12个月',
//            '历史数据布尔近12个月',
//            '布尔近12个月',
//            '历史数据雷达近24个月',
//            '雷达近24个月',
//            '历史数据布尔近24个月',
//            '布尔近24个月',
//        ];
//        $title = "jj逾期用户还款比";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
//
//        $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('m.cert_no','<>','')
//            ->where('m.cert_no','<>','0')
//            ->groupBy('m.id')
//           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455','070314212534'])
//           ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time',
//               'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->orderBy('id','desc')
//           ->limit(1000)
//           ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] =$value['sale_user_id']=='070314212534'?'bp':'fql';
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '商品名称',
//            '订单金额',
//            '渠道'
//        ];
//        $title = "用户订单";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
////
//        //发送法诉短信
//        $res=parseFile('/www/wwwroot/www.doulaizu.com/public/cba.csv');
//        $i=0;$a=0;
//        foreach ($res as $key=>$data) {
//            if($key==0){
//                continue;
//            }
//           $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->where('o.trade_no','20230626160409770705')
//           ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.id','s.member_id','o.uid','o.seller_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title')
//           ->first()->toArray();
//           $sexint = (int) substr($user['cert_no'], 16, 1);
//           $gender= $sexint % 2 === 0 ? '女士' : '先生';
//
//           $data = array();
//           $data['content'] = '[债权转让通知]'.$user['cert_name'].$gender.':您通过【都来租物】申请的 '.$user['goods_title'].$user['setmeal_title'].'手机租赁业务，
//           订单编号:【'.$user['trade_no'].'】2024年9月14日'.$user['mechanism'].'与崇信云盛科企业管理服务有限公司达成的债权转让协议，现将我公司对您的所有债权，依法转让给崇信云盛科企业管理服务有限公司，此转让债权相关的其他权利也一并转让，请您自接到该债权转让通知书后【3】日内向崇信云盛科企业管理服务有限公司履行全部义务。专此通知。';
//           // dd( $data['content']);
//           $send_res=SmsService::send_msg($user['mobile'],$data['content']);
//           var_dump($user['trade_no']);
//           var_dump($send_res);
//           if($send_res['status']){
//               $send_status = 1;
//               $reason = 'OK';
//           }else{
//               $send_status = 2;
//               $reason = $send_res['msg'];
//           }
//
//           $data['order_id'] = $user['trade_no'];
//           $data['mobile'] = $user['mobile'];
//           $data['member_id'] =$user['member_id'];
//           $data['template_id'] ='26';
//           $data['reason'] = $reason;
//           $data['send_user'] = $user['uid'];
//           $data['send_status'] = $send_status;
//           $data['create_time'] = date('Y-m-d H:i:s');
//           SmsRecord::insert($data);
//        }



//        exit();
//        return;
//        //上传拿货价
//       $res=parseFile('/www/wwwroot/www.doulaizu.com/public/cba.csv');
//       $i=0;$a=0;
//           foreach ($res as $data) {
//           $orderId=Order::where('trade_no',$data[0])->where('seller_id','<>',1704471788)->value('id');
////               var_dump($data);
////           dd($orderId);
//               if($orderId&&$data['2']){
//              $res=OrderGoods::where('order_id',$orderId)->update(['acquisition_price'=>$data['2'],'device_number'=>$data['1']]);
////                   if($res!==false){
//                       var_dump($a++.'--'.$res);
//                       var_dump($i+=$data['2']);
////                   }
//                }else{
//                   var_dump($data[0]);
//               }
//            }
//           exit();
//       return ;
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->whereIn('o.status',['30'])
//            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.id as order_id','o.uid','o.seller_id','o.status','o.create_time')
//            ->orderBy('o.id','desc')
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['trade_no'];
//        }
//        $headList = [
//            '身份证',
//            '订单状态',
//            '订单时间',
//            '订单号',
//        ];
//        $title = "订单数据";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);

//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->where('m.level_performance','<>','')
//            ->where('m.level_performance','<>','0')
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->select('m.mobile','m.cert_name','m.cert_no','m.level_performance','o.id as order_id','o.uid','o.seller_id','o.status')
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = $value['level_performance'];
//        }
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('m.cert_no','<>','')
//            ->where('m.cert_no','<>','0')
//            ->where('m.level_performance','<>','')
//            ->where('m.level_performance','<>','0')
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->groupBy('m.id')
//            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','m.level_performance','o.create_time','o.status',
//                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->orderBy('id','desc')
//            ->limit(1000)
//            ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = $value['level_performance'];
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '套餐信息',
//            '订单金额',
//            '订单状态',
//            '履约等级',
//        ];
//        $title = "jj1-2用户的履约等级";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);

      $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
          ->where('o.seller_id','1704471788')
//           ->where('o.area','like','%宜都市%')
          ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
          ->select(
               'm.openId','o.id','o.trade_no','o.location','o.status','s.shopname',
               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from',
               'm.mobile','m.cert_name',
           )->whereIn('o.status',['30','38','39'])->orderBy('id','asc')->groupBy('o.trade_no')->get()->toArray();

       foreach ($order as $key=>$value) {
           $dataInfo[$key][] = $value['shopname'];
           $dataInfo[$key][] = "\t".$value['trade_no'];
           $dataInfo[$key][] = $value['cert_name'];
           $dataInfo[$key][] = "\t".$value['mobile'];
           $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
           $orderLease =OrderLease::where('order_id',$value['id'])->where('overdue_days','>=',1)->orderBy('id','asc')->select('begin_time','id')->first();
           $dataInfo[$key][] = $orderLease?date('Y-m-d',$orderLease['begin_time']):'';
           $dataInfo[$key][] = OrderLease::where('id',$orderLease['id'])->value('rent');
           $begin_time =OrderLease::where('id',$orderLease['id'])->where('status',1)->orderBy('id','desc')->value('pay_time');
           $dataInfo[$key][] = $begin_time?date('Y-m-d',$begin_time):'';
           $dataInfo[$key][] = OrderLease::where('id',$orderLease['id'])->value('paid_rent');
       }
       $headList = [
           '商家名称',
           '订单编号',
           '姓名',
           '手机号码',
           '订单状态',
           '首次逾期时间',
           '逾期金额',
           '最新还款的时间',
           '还款金额',
       ];

       $title = "逾期订单";

       //调用上面的方法
       return  csvExporta($dataInfo, $headList, $title);

    }

    public function testAto(Request $request){

//        AntchainAtoServicejuzu::cancelWithholdPlan('2025052401535133690337');
//        AntchainAtoServicejuzu::closeOrder('2025052401535133690337');
//        return  AntchainAtoServicejuzu::asyncUnbindConfirm('2025052401535133690337', "AGREE", null, 0, null);
//         return  AntchainAtoServicejuzu::createWithholdRefund('2025051802430629271342',3,'40104');

        return AntchainAtoServicejuzu::getTradeUserperformance('2025051802430629271342');
//
return  AntchainAtoService::queryOrder('2025060400220988773608',1,'42708');
        // return  AntchainAtoService::createWithholdRefund('2025052810224586012809',1,'55625');
//return var_dump(obToArray($obj));
//        AntchainAtoService::repayWithholdPlan($order['trade_no'], 1, $lease['rent']);

//   return   AntchainAtoService::queryWithholdRefund('2025052514151590257652',1);

        return  AntchainAtoService::getTradeUserperformance('2025060316591979460954');

        $order=Order::query()->from('sp_order_2 as o')
            ->leftJoin('sp_order_lease_2 as a', 'o.id', 'a.order_id')
            ->where('a.which_period','1')
            ->where('a.status',1)
            ->where('a.pay_type','>',1)
            ->select('o.trade_no','a.rent')
            ->get();

        $order=obToArray($order);
        foreach ($order as $key=>$value){
            usleep(200000);
             $res= AntchainAtoService::repayWithholdPlan($value['trade_no'], 1,$value['rent']);
             var_dump($res);
        }
exit();
       // AntchainAtoService::repayWithholdPlan('2025052614050996830698', 1, bcsub(656.25,  534.37, 2));

        return  AntchainAtoService::getTradeUserperformance('2025052301244560791340');


//        $counta=OrderRemark::query()->from('sp_order_remark_2 as r')
//            ->where('r.remark','(申请取消代扣协议)')
//            ->groupBy('r.order_id')
//            ->leftJoin('sp_order_2 as o', 'r.order_id', 'o.id')
//            ->leftJoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->select('r.order_id','r.create_time','o.trade_no','o.mobile','o.status','og.goods_title')
//            ->get();
//        $counta=obToArray($counta);
//        var_dump(count($counta));
//        foreach ($counta as $k=>&$v){
//
//            if($v['status']=='39'||$v['status']=='38'){
//                $user_owe_money=OrderLease::query()->where('order_id',$v['order_id'])->where('status',4)->sum('rent');
//                $one= AntchainAtoService::asyncUnbindConfirm($v['trade_no'], "REFUSE", null, bcmul($user_owe_money, 100), 'USER_OWE_MONEY');
//            }else if($v['status']=='60'||$v['status']=='1'||$v['status']=='16'){
//                AntchainAtoService::cancelWithholdPlan($v['trade_no']);
//                AntchainAtoService::closeOrder($v['trade_no']);
//                $one= AntchainAtoService::asyncUnbindConfirm($v['trade_no'], "AGREE", null, 0, null);
//            }else{
//                $year=date('Y年',$v['create_time']);
//                $reason=$year.$v['goods_title'].'订单';
//                $one= AntchainAtoService::asyncUnbindConfirm($v['trade_no'], "REFUSE", $reason, 0, 'USER_IN_SERVICE');
//            }
//
//
//            $one['status']=OrderService::getOrderStatusName($v['status']);
//            $one['trade_no']=$v['trade_no'];
//            $one['date']=date('Y-m-d H:i:s',$v['create_time']);
//            $one['mobile']=$v['mobile'];
//            \Illuminate\Support\Facades\Log::channel("otherlog")->debug('处理代扣协议',$one);
//            usleep(300000); // 休眠 0.1 秒
//            var_dump($one);
//        }
//   return $counta;
///
//        AlipayMessageService::sendChangeOrderMessage(10553,AlipayMessageService::KX_SHOPPING);
////        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::KX_SHOPPING);
//exit();
////     SendChangeOrderMessage::dispatch(10553,AlipayMessageService::CONSUMER,'BILLED');
//        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::CONSUMER,'PAY_WAITING');
//        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::CONSUMER,'OVERDUE');


//        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::KX_SHOPPING);

//        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::CONSUMER,'PAYMENT_S');
//        SendChangeOrderMessage::dispatch(10553,AlipayMessageService::CONSUMER,'PAID_OFF');
// return  AntchainAtoService::repayWithholdPlan('2025051314164786922168',1,'635.41');

        return  AntchainAtoService::getTradeUserperformance('2025052300094619282133');
//
//        return  AntchainAtoService::queryOrder('2025051807444987944817');
//     return  AntchainAtoService::createWithholdRefund('2025051807444987944817',1,'65625');
//exit();
//        return SendChangeOrderMessage::dispatch('10553',AlipayMessageService::KX_SHOPPING);

        AntchainAtoService::cancelWithholdPlan('2025051819195482679273');
           AntchainAtoService::closeOrder('2025051819195482679273');
        return  AntchainAtoService::asyncUnbindConfirm('2025051819195482679273', "AGREE", null, 0, null);
        return AntchainAtoService::queryWithholdSign('2025051418280019379025');
    return    SendChangeOrderMessage::dispatch(10446,AlipayMessageService::CONSUMER);


        // $value = AppTypeService::getByMiniId(1);

        $list = AppTypeModel::get()->toArray();

        $list = DXUtil::formatModelList($list, function ($item) {

            $item['name'] = "whis";

            return $item;
        });


        return ReturnMsg(200,'登录成功',['rst' => $list]);

    }

       public function useTest(Request $request){
                  $order = Order::from('sp_order_2 as o')->where('o.id',29239)
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
               ,'m.cert_name','m.cert_no','o.sale_user_id','o.prov'
               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
           )
           ->first();
       return RiskDlzwService::shopInquire($order);

//           $body = [
//               "merchant_id" => 'HZZ0728',
//               "encrypt_data" =>'R/dxMEjG05Tv/O3+0RhVVArXluJrxc+l4DBUw+uKIQRquxqWHLUaUBCfPgjgEopWrIQFvqz7BMUrV1nuxIrSYwaMZh7mU2Yw3AjWzuYhIAVt1kFACFQMznaHNjTt4gTGs9VhY6GPeXeaFgDflyuJcaaffiEom9PsrHRrDa8Cf2sBTedTThtw3KyjMHjFhrYsQCYGXNQF7XiMVQKEy9VCjX1NDNbS7+GhWsyrKM7Ox2neOChvbF0La48kBguqUNCwRNwxUp3rykJYjjKjIpso89+f3ggbK7dTKDdsHe3tLBMPw2t6HkuaVfAr3tYKoxN0VILc66pNfd/r3IPqBBohkA==',
//               "time_stamp" => '1753698268276',
//           ];
//
//           $sign= RiskDlzwService::getSign('HZZ02p9J0lx24n4D8UnX31nGfNul16mNbuT2AFfHZumig60QhSk7H5IhvMYj6OKHL',$body);
//
//dd($sign);

    ProcessPodcast::dispatch('21301');
    exit();

           $post = Order::from('sp_order_2 as o')->where('o.id','21233')
               ->leftjoin('sp_member_2 as m','m.id','o.uid')
               ->select(
                   'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
                   ,'m.cert_name','m.cert_no','o.sale_user_id','o.prov','o.location','o.city','o.prov','o.area'
                   ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
               )
               ->first();


           if($post['location']&&$post['city']&&strpos($post['location'],$post['city'])=== false&&
               $post['location']&&$post['area']&&strpos($post['location'],$post['area'])=== false||
               $post['location']&&$post['prov']&&strpos($post['location'],$post['prov'])=== false
           ){
              return RelationVerifyService::ColseOrder($post['id'],'下单定位与收货地址不一致');
           }

           exit();

           return Redis::del('user_order_limit_crate_order_black_161617');
       $OrderDepict['order_id']=11045;
       $begin_time=OrderLease::where(['order_id' => $OrderDepict['order_id']])->where('which_period',1)->value('begin_time');
       $addTime=time()-$begin_time;
       $status=Order::query()->where(['id' => $OrderDepict['order_id']])->value('status');

       if($addTime>0&&$status<=10){
           DB::beginTransaction();
           OrderLease::query()->where('order_id',$OrderDepict['order_id'])->increment('begin_time',$addTime);
           OrderLease::query()->where('order_id',$OrderDepict['order_id'])->increment('end_time',$addTime);
           Db::commit();
           Log::channel('otherlog')->info('订单时间增加',['addTime'=>$addTime,'order_id'=>$OrderDepict['order_id']]);
       }
       return $status;

       $checkLease = OrderLease::where(['order_id' => 10653, 'status' => OrderLease::ORDER_LEASE_STATUS_OVERDUE])->select('id')->get();
       return obToArray($checkLease);

        return Redis::del('user_order_limit_crate_order_black_160049');
       return AntchainAtoServicejuzu::getTradeUserperformance('2025051801400655734989');
       $order = Order::where('id', '11778')
           ->select('id', 'mini_id', 'trade_no', 'rent_total', 'rights_auth_no', 'foregift', 'month_total',
               'amount', 'uid', 'status', 'address', 'mobile', 'realname')
           ->first();
       $order = $order ? $order->toArray() : [];

       $order_goods = OrderGoods::from('sp_order_goods_2 as og')->select('og.goods_title', 'og.id','og.setmeal_foregift', 'og.pact_type', 'c.rent_category')
           ->leftjoin('sp_goods_2 as g', 'g.id', 'og.goods_id')
           ->leftjoin('sp_category as c', 'c.id', 'g.category_id')
           ->where('og.order_id', '10419')
           ->first();
       $order_goods = $order_goods ? $order_goods->toArray() : [];

       $data['mini_id'] = $order['mini_id'];
       $data['userAlipayUId'] = $this->member['user_id'];
       $data['rentPeriod'] = $order['month_total'] * 30;
       $data['rentAmount'] = $order['rent_total'];
       $data['orderNo'] = $order['trade_no'];
       $data['goodsTitle'] = $order_goods['goods_title'];
       $data['goodsId'] = $order_goods['id'];
       $data['notifyUrl'] = config('alipay.callbackDomain') . CommonService::NOTICE_XXZ_URL_PAY;
       $ali_res = AlipayService::creditbizorderCreatePay($order['mini_id'], $data);


return $ali_res;

        SendSmsMessageJob::dispatch(SmsTempEnum::PENDING_PAYMENT,'13886');
exit();
       $order=Order::query()->where('id',11701)->where('create_time','>',1748602538)->select('id')->get();
// dd(count($order));
foreach ($order as $ra){
    var_dump($ra['id']);
    $res=(new Order)->orderCheckAutoPass($ra['id']);
    var_dump($res);

}
return;
             return   (new Order)->orderCheckAutoPass('11773');

      return  AntchainAtoService::queryWithholdSign('2025052514151590257652');
//       $order = Order::from('sp_order_2 as o')->where('o.id',11443)
//           ->leftjoin('sp_member_2 as m','m.id','o.uid')
//           ->select(
//               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
//               ,'m.cert_name','m.cert_no','o.sale_user_id','o.prov'
//               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
//           )
//           ->first();
//       if(!empty($order['cert_no'])) {
//           RiskDlzwService::shopInquire($order);
//       }
//       exit();

       SendSmsMessageJob::dispatch(SmsTempEnum::ORDER_REJECTED,'11443');exit();
      ChargeService::smsUseConfigTemplate(SmsTempEnum::ORDER_REJECTED,'11443');
       exit();
//       exit();
       SendSmsMessageJob::dispatch(SmsTempEnum::ORDER_APPROVED,'11050');

       exit();
             $user=MemberOther::query()->where('mobile','>','0')->where('cert_no','0')->select('mobile')->get();
             foreach ($user as $item){
                 $content = '您在潮省心商城下单的 苹果手机数码产品 审核已经通过，可上"支付宝" 搜索“潮省心商城“确认收获信息哟，当天4小时内发货哟，https://u.alipay.cn/_2reMG8e9audfDJrtmfV5Yz';
                 $send_res=SmsService::send_msg($item['mobile'],$content);
                 var_dump($send_res);
             }
exit();

       $listApp=AppTypeModel::query()->select('id','app_name')->get();


       $groupData=['home_active','home_field','great'];

       foreach ($listApp as $item){
           $mini_id=$item['id'];

           $app_name=AppTypeModel::query()->where('id',$mini_id)->value('app_name');
           if(!empty($mini_id)&&$mini_id==10009){
               $open=0;
               $name=compact('app_name','open');
           }else{
               $name=compact('app_name');
           }
           $jsonContent = json_encode($name, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$mini_id.'app_name.json';
           file_put_contents($path,$jsonContent);
           $fileName=$mini_id.'app_name.json';
           AlipayService::upload($fileName,$path);

          foreach ($groupData as $group){

              $data=AppMiniPlate::getAlipayMiniPlate($mini_id,$group);

              $jsonContent = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
              $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$mini_id.$group.'.json';
              file_put_contents($path,$jsonContent);
              $fileName=$mini_id.$group.'.json';
              var_dump($fileName);
              AlipayService::upload($fileName,$path);
          }

       }
       return ReturnMsg(200);


       // 延迟 10 分钟执行10274
       //10273
       //10272
       //10270
       //10235
       //10234

     ProcessPodcast::dispatch('10273');
     exit('1234561');
     return  ProcessPodcast::dispatch($podcast);


       $order = Order::from('sp_order_2 as o')->where('o.id',10227)
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
               ,'m.cert_name','m.cert_no','o.sale_user_id','o.prov'
               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
           )
           ->first();

       if(empty($order['cert_no'])){
           return ReturnMsg(CommonService::HTTP_CODE_FAIL,'用户身份证未上传');
       }
       $res=RiskDlzwService::shopInquire($order);

     return $res;

//       return AntchainAtoService::queryOrder('20241202140742363838');
//        return AntchainAtoService::uploadSignTemplate();
return EsignV3Service::getAuthFlowUrl();

       $order = Order::from('sp_order_2 as o')->where('o.id',10002)
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
               ,'m.cert_name','m.cert_no'
               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
           )
           ->first();



     return  $result=EsignV3Service::createBoolUserAuth($order);

       $pdfFile = '/www/wwwroot/api.qianbaozuji.com/public/pdf/20241119162331726427.pdf'; // PDF文件路径
       $outputDir = '/www/wwwroot/api.qianbaozuji.com/public/pdf/'; // 输出图片文件路径
       $density = 100;

// 创建Imagick对象
       // 创建 Imagick 对象
       $imagick = new \Imagick();
       $imagick->setResolution($density, $density);
       $imagick->readImage($pdfFile);

// 转换为图片
       $imagick->setImageFormat('jpeg');

       for ($i = 0; $i < $imagick->getNumberImages(); $i++) {
           $imagick->setIteratorIndex($i);
           // 获取当前页面的尺寸
           $dimensions = $imagick->getImageGeometry();
           $width = $dimensions['width'];
           $height = $dimensions['height'];

           // 创建一个新的白色背景的图像
           $newImage = new \Imagick();
//         $newImage->setFont('hp.ttf');
           $newImage->newImage($width, $height, new \ImagickPixel('white'));

           // 合并原图和新图
           $newImage->compositeImage($imagick, \Imagick::COMPOSITE_OVER, 0, 0);
           // 保存图片
           $newImage->writeImage($outputDir . '20241119162331726427-' . ($i + 1) . '.jpeg');

           // 清理资源
           $newImage->clear();
           $newImage->destroy();
       }
// 写入图片文件

// 清理资源
       $imagick->clear();
       $imagick->destroy();

       echo "PDF页面已转换为图片: ";exit();

       $fileName = "20241119170754140560.pdf";
       $path = '/www/wwwroot/api.qianbaozuji.com/public/pdf/20241119170754140560.pdf';
       if (chmod($path, 0644)) {
           echo "权限设置成功";
       } else {
           echo "权限设置失败";
       }
       var_dump(chmod($path, 0755));exit();
       $uploud_res = AlipayService::upload($fileName,$path);
       var_dump($uploud_res);exit();

       return EsignV3Service::createEvil();
        return EsignV3Service::personAuth(['mobile'=>'17779146889']);
//              $res=EsignService::createByUploadUrl();
//       dd($res);
     $cert_no=MemberQnRisk::where('risk_result','=','10')->pluck('cert_no');
     return $cert_no;
       $user=Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->whereIn('m.cert_no',$cert_no)
            ->whereIn('o.status',['10','20','30','38','39'])
            ->select(
                'o.id','o.status',
                'm.cert_no','m.cert_name','m.mobile','o.trade_no'
            )
            ->get();
       $user=obToArray($user);
       foreach ($user as $key=>$value) {
           $dataInfo[$key][] = "\t".$value['trade_no'];
           $dataInfo[$key][] = $value['cert_name'];
           $dataInfo[$key][] = $value['mobile'];
           $dataInfo[$key][] =  OrderService::getOrderStatusName($value['status']);
       }
       $headList = [
           '订单号',
           '姓名',
           '电话',
           '状态',
       ];
       $title = "qn通过-都来租物";
       //调用上面的方法
       return  csvExporta($dataInfo, $headList, $title);

//       $user= Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//       ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//       ->where('m.cert_no','>',0)
//       ->groupBy('o.uid')
//      ->orderBy('o.create_time','desc')
//       ->select(
//       'o.id','m.cert_no','m.cert_name','m.mobile','o.trade_no'
//       )
//           ->offset(20)
//           ->limit(30)->get();
//       $user=obToArray($user);
//       foreach ($user as $key=>$value) {
//           $dataInfo[$key][] = "\t".$value['trade_no'];
//           $dataInfo[$key][] = $value['cert_name'];
//           $dataInfo[$key][] = $value['mobile'];
//           $dataInfo[$key][] =json_encode(XinyanService::fsData($value), JSON_UNESCAPED_UNICODE);
//       }
//       $headList = [
//           '订单号',
//           '姓名',
//           '电话',
//           '风控结果',
//       ];
//       $title = "风控结果";
//       //调用上面的方法
//       return  csvExporta($dataInfo, $headList, $title);

//       $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m','m.id','o.uid')
//           ->groupBy('o.uid')
//           ->where('m.cert_no','>',0)
//           ->where('o.create_time','>',time()-3600*3)
//           ->select(
//               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_5','o.trade_no'
//               ,'m.cert_name','m.cert_no','o.sale_user_id'
//               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
//           )
//           ->orderBy('o.id','desc')
//           ->get();
//       foreach ($user as $key=>$value) {
//          $res=RiskQnypService::query($value);
//          var_dump($res);
//       }
//       exit();
//
////       return WechatService::getFundFlow('4200002447202410090764892837','958.23');
//
//       $res=Order::from('sp_order_2 as o')
//           ->whereIn('o.seller_id',[1704471788,1704471738])
//           ->where('o.status','39')
//           ->select('o.id','o.trade_no')
//           ->get()->toArray();
//       foreach ($res as $key=>$value){
//           $resa=OrderLease::where('status',4)->where('order_id',$value['id'])->orderBy('id','desc')->first()->toArray();
//           //var_dump(date('Y-m-d H:i:s',$resa['begin_time']));
//           if($resa['begin_time']>=1728057600){
//      var_dump($value);
//            Order::where('id',$value['id'])->update(['status'=>38]);
//           }
//       }
//exit();
//
//        $RelationVerifyService=new RelationVerifyService();
//        return $RelationVerifyService->lawSuitPersonal(['cert_no'=>'440582199504144214','cert_name'=>'陈悦鹏','order_id'=>100]);
//
//      return Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->where('o.seller_id','202309081070080001')
//          ->where('o.sale_user_id','012610463751')
//          ->groupBy('o.uid')
//           ->pluck('m.cert_no');
//
//
//   $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_order_goods_2 as og', 'og.order_id', 'o.id')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->where('og.pact_type','1')
//           ->where('og.setmeal_price','>',0)
//           ->whereIn('o.status',[30,60])
//           ->where('o.seller_id','<>',1704471788)
//           ->select(
//           'o.id','o.trade_no','m.cert_name','o.uid'
//           )->get()->toArray();
//   foreach ($user as $key=>$value){
//       $res=OrderLease::where('order_id',$value['id'])->where('status',1)->count();
//       $resa=OrderLease::where('order_id',$value['id'])->count();
//       if($resa==$res){
//           $count=Order::where('status',30)->where('uid',$value['uid'])->where('id','>',$value['id'])->count();
//           if(!$count){
//               var_dump($value);
//           }
//       }
//   }
//   exit();
//
////        return WechatService::createUserQrCode('11');
////        return AlipayService::AlipayDataBillSellQueryRequest('20240916200040011100850024165274',1);
//       $user= Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//       ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//       ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//       ->select(
//       'o.id','ol.rent',
//       'm.openId','m.cert_name','m.mobile','o.trade_no','ol.id as lease_id'
//       )->where('ol.status',1)->where('o.status','>=',30)->where('o.seller_id',1704471788)->get();
//       $user=obToArray($user);
//       foreach ($user as $key=>$value) {
//           $dataInfo[$key][] = "\t".$value['trade_no'];
//           $dataInfo[$key][] = $value['cert_name'];
//           $dataInfo[$key][] = $value['mobile'];
//           $dataInfo[$key][] = OrderLease::where('id',$value['lease_id'])->value('which_period');
//           $dataInfo[$key][] =OrderLease::where('id',$value['lease_id'])->value('rent');
//       }
//       $headList = [
//           '订单号',
//           '姓名',
//           '电话',
//           '期数',
//           '金额',
//       ];
//       $title = "享惠租物";
//       //调用上面的方法
//       return  csvExporta($dataInfo, $headList, $title);
//
//       $alipay_data['alipay_trade_no'] = '20240920368821647205';
//       $alipay_data['rights_auth_no'] = '2024092010002001720567921567';
//       $alipay_data['query_options'] = ['credit_risk_info'];
//
//       $prequery = AlipayService::alipayCreditPreQuery($alipay_data);
//       dd($prequery);

       return WechatService::getFundFlow('4200002447202410090764892837','958.23');
        return  AlipayService::createUserShopQrCode('1678175782','盈都租机');
//       return $data=EsignService::checkFaceStatusAuth('3526231918050284381');
//
//          $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->select(
//               'o.id','o.trade_no',
//           )->where('o.status',30)->orderBy('id','asc')->groupBy('o.trade_no')->get()->toArray();
//
////       return $order;
////     return count($order);
//       $num=0;
//       $name=[];
//       foreach ($order as $key=>$value){
//           $rent=OrderLease::where('order_id',$value['id'])->sum('rent');
//           $rent_paid=OrderLease::where('order_id',$value['id'])->sum('paid_rent');
//           if($rent_paid>=$rent&&$rent>0){
//               $num++;
////               $name[]=$value['cert_name'];
//               var_dump($value['trade_no']);
//               $add = [
//                   'uid'=>23,
//                   'username'=>'系统',
//                   'create_time'=>time(),
//                   'remark'=>'还款完成，订单完成',
//                   'order_id'=>$value['id']
//               ];
//               OrderRemark::insert($add);
//               Order::where('id',$value['id'])->update(['status'=>60]);
//           }
//       }
//       exit();

//       return  AntchainAtoService::closeOrder('20240626131820941321');

//       return AntchainAtoService::asyncUnbindConfirm('20240626131820941321', "AGREE", null, 0, null);

//       $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->where('o.trade_no','20230626160409770705')
//           ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.realname','o.mobile','o.address',
//               'o.month_total','o.address','o.address',
//               'o.id','s.member_id','o.uid','o.seller_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title')
//           ->first()->toArray();
//       $user['rent']=OrderLease::where('order_id',$user['id'])->where('which_period','1')->value('rent');
//      return  AlipayService::rentriskQuery($user);
//exit();
//       $order= Order::from('sp_order_2 as o')
//                    ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//                    ->where('o.sale_user_id','022215565466')
//                    ->where('o.sign_no','>','0')
//                    ->where('ol.which_period','2')
//                    ->where('ol.status','1')
//                    ->where('ol.pay_type','8')
//                    ->groupBy('ol.order_id')
//                    ->select('o.id','o.trade_no','o.sign_no','o.status','o.seller_id','o.sale_user_id','ol.out_order_no','ol.pay_type','ol.status as ol_status','ol.overdue_amount','ol.overdue_days','ol.rent','ol.which_period')
//                    ->get();
//                return obToArray($order);
//     return  AntchainAtoService::queryWithholdSign('20240619113808929520');

//  return  AntchainAtoService::repayWithholdPlan('20240720135617738195',2,'1916.47');

//    return AntchainAtoService::createWithholdRefund('20240720135617738195',2,191647);
// return  AntchainAtoService::queryWithholdRefund('20240720135617738195',2);


//        return Db::table('sp_extension_statistics')
//            ->whereIn('sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455'])
//            ->distinct('http_user_agent')
//            ->where('create_time','<','1720713600')
//            ->count();

              $cert_nos= Order::from('sp_order_2 as o')
            ->where('o.status','39')
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455'])
           ->groupBy('m.id')
           ->pluck('m.id');
              dd($cert_nos);
           $user= Order::from('sp_order_2 as o')
               ->leftjoin('sp_member_2 as m','m.id','o.uid')
               ->whereIn('m.id',$cert_nos)
               ->where('m.level_performance','<>','')
               ->where('m.level_performance','<>','0')
               ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455'])
               ->groupBy('o.uid')
               ->select('m.mobile','m.cert_name','m.cert_no','m.level_performance','o.id as order_id','o.uid','o.seller_id')
               ->get();
       $user=obToArray($user);
     foreach ($user as $key=>$value) {
         $dataInfo[$key][] = $value['cert_name'];
         $dataInfo[$key][] = $value['mobile'];
         $dataInfo[$key][] = $value['level_performance'];
       }
       $headList = [
           '姓名',
           '电话',
           '履约等级',
       ];
       $title = "分期乐逾期用户的履约等级";
       //调用上面的方法
       return  csvExporta($dataInfo, $headList, $title);
//
     return count($cert_no);
       set_time_limit(0);
       ini_set('memory_limit', '-1');
       $user= Order::from('sp_order_2 as o')
           ->where('o.seller_id','202309081070080001')
           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
           ->where('o.create_time','>','1720800000')
           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455'])
           ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.id as order_id','o.uid','o.seller_id')
           ->orderBy('o.id','desc')
           ->offset(2000)
           ->limit(1100)
           ->get()->toArray();
//      return  XinyanService::fxRadar($user);

//       $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->where('o.sale_user_id','071013291497')
//           ->where('o.seller_id','1678175782')
//           ->where('o.status','4')
////           ->where('m.cert_name','<>','0')
//           ->groupBy('o.uid')
//           ->orderBy('o.id','desc')
//           ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.id as order_id','o.uid','o.seller_id')
//           ->get()->toArray();
//
   $RelationVerifyService=new RelationVerifyService();
       foreach ($user as $key=>$value){
          $RelationVerifyService->lawSuitPersonal($value);
             $dataInfo[$key][] = $value['cert_name'];
             $dataInfo[$key][] = $value['mobile'];
             $dataInfo[$key][] =MemberLegal::where(['uid'=>$value['uid']])->value('is_legal');
       }
      $headList = [
           '姓名',
           '电话',
           '是否法诉0为法诉',
       ];
       $title = "分期乐法诉查询";
       //调用上面的方法
       return  csvExporta($dataInfo, $headList, $title);
     return $user;






//        $RelationVerifyService=new RelationVerifyService();
//        return $RelationVerifyService->rentQualifyScore(['cert_no'=>'620123199407216118','cert_name'=>'邴建礼','mobile'=>'15393103307']);


//       return AlipayRealpersonService::main('夏啟超','53230120040311151s');
//              $res=EsignService::createByUploadUrl();
//       dd($res);
//         return NotarizeService::notaryQuery('20240701110123345807001');
//        exit();
//        return  Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->where('o.seller_id',1678175782)
//           ->select(
//               'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
//               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
//               , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//               , 'm.mobile','m.cert_name',
//           )->whereIn('o.status',['30'])
//            ->where('og.pact_type',1)->orderBy('id','asc')->distinct('o.trade_no')->count();
//        $order= Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->where('o.sign_no','>','0')
//           ->where('o.withhold_status','1')
//           ->whereIn('o.status',['1','16'])
//           ->get()->toArray();
//        foreach ($order as $ra){
//            $lease=OrderLease::where('order_id',$ra['id'])->where('which_period','2')->value('paid_rent');
//            if($lease>0){
//                var_dump($ra['trade_no']);
//            }
////            $res=AntchainAtoService::queryOrder($ra['trade_no']);
////            $orderStatus=json_decode($res['responseData'],true)['orderStatus'];
////            if($orderStatus=='OPEN'){
////                AntchainAtoService::cancelWithholdPlan($ra['trade_no']);
////                AntchainAtoService::closeOrder($ra['trade_no']);
////                AntchainAtoService::asyncUnbindConfirm($ra['trade_no'], "AGREE", null, 0, null);
////                var_dump($ra['trade_no']);
////            }else{
////
////            }
//        }
// dd(count($order));
  return AntchainAtoService::queryOrder('2025051418280019379025');
//       return json_decode($res['responseData'],true)['orderStatus'];
//
//       //创建退款
//return AntchainAtoService::createWithholdRefund('20240624143736634496',2,123316);
// return  AntchainAtoService::queryWithholdRefund('20240624143736634496',2);

//       // 代扣是否签约成功
// return  AntchainAtoService::queryWithholdSign('20240624143736634496');
//       //还款记录

//     return  AntchainAtoService::getTradeUserperformance('20240706110055397482');
//        //取消某一期代扣
//  return  AntchainAtoService::repayWithholdPlan('20240726160311344709',1,'574.90');
////关闭订单
// return AntchainAtoService::closeOrder('20240626163240509140');
//       //关闭代扣
// return AntchainAtoService::cancelWithholdPlan('20240626163240509140');
//  return AntchainAtoService::asyncUnbindConfirm('20240626131820941321', "AGREE", null, 0, null);
// //        return WechatService::getLinkUrl();
// //       $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
// //           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
// //           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
// //           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
// //           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
// ////           ->where('o.seller_id',1685775283)
// //           ->select(
// //               'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
// //               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
// //               , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
// //               , 'm.mobile','m.cert_name',
// //           )->where('o.status',30)
// //            ->where('og.pact_type',2)->orderBy('id','asc')->groupBy('o.trade_no')->get()->toArray();
// //
// ////       return $order;
// ////     return count($order);
// //       $num=0;
// //       $name=[];
// //       foreach ($order as $key=>$value){
// //           $rent=OrderLease::where('order_id',$value['id'])->sum('rent');
// //           $rent_paid=OrderLease::where('order_id',$value['id'])->sum('paid_rent');
// //           if($rent_paid>=$rent){
// //               $num++;
// //               $name[]=$value['cert_name'];
// //               Order::where('id',$value['id'])->update(['status'=>60]);
// //           }
// //       }
// //       return $name;
// //       //           Order::where('id',$value['id'])->update(['status'=>60]);
// //
// //       return $order;
// //
// //
// //
// //       $num = 0;
// //       foreach ($user as $key=>$value) {
// //           // 序号
// //           $cert_no_a=substr($value['cert_no'],0,3);
// ////           if(!in_array($cert_no_a,['330','350','360'])){
// ////               continue;
// ////           }
// //           $dataInfo[$key][] = $value['cert_name'];
// //           $dataInfo[$key][] = getAgeByID($value['cert_no']);
// //           $dataInfo[$key][] = "\t".$value['cert_no'];
// //           $dataInfo[$key][] = OrderLease::where('order_id',$value['id'])->where('status','<>',1)->sum('rent');
// //           $dataInfo[$key][] = OrderLease::where('order_id',$value['id'])->where('status','<>',1)->sum('overdue_amount');
// //           $dataInfo[$key][] = $cert_no_a==330?'浙江':($cert_no_a==350?'福建':($cert_no_a==360?'江西':'其他'));
// //
// //       }
// //       $headList = [
// //           '姓名',
// //           '年龄',
// //           '身份证号',
// //           '诉讼本金（逾期金额）',
// //           '利息（逾期费）',
// //           '户籍地',
// //       ];
// //
// //       $title = "盈都租机逾期";
// //
// //       //调用上面的方法
// //       return  csvExporta($dataInfo, $headList, $title);
// //       exit();
// //
// //           $orders= Order::from('sp_order_2 as o')
// //           ->leftjoin('sp_order_lease_2 as ol','ol.order_id','o.id')
// //           ->where('o.seller_id',1685775283)
// //           ->where('ol.status',1)
// //           ->where('ol.begin_time','>','1713196800')
// //           ->where('ol.begin_time','<','1714752000')
// //           ->sum('ol.rent');
// //           return $orders;
// //
// ////       $orders= Order::from('sp_order_2 as o')
// ////           ->leftjoin('sp_member_2 as m','m.id','o.uid')
// ////           ->where('o.status',39)
// ////           ->orderBy('o.id','asc')
// ////           ->select('m.cert_name','m.mobile','m.cert_no','m.openId')
// ////           ->limit(50)
// ////           ->get()
// ////           ->toArray();
// //     $RelationVerifyService=new RelationVerifyService();
// ////       foreach ($orders as $key=>$value){
// ////            $ra=$RelationVerifyService->blackListQuery(['mobile'=>$value['mobile'],'cert_no'=>$value['cert_no'],'cert_name'=>$value['cert_name']]);
// ////            var_dump($value['cert_name']); var_dump($ra['data']);
// ////       }
// ////       exit();
// ////       return $RelationVerifyService->blackListQuery(['mobile'=>'17645184623','cert_no'=>'231225199903204016','cert_name'=>'韩所']);
// //
// //       return $RelationVerifyService->query(['mobile'=>'18944310376','provider'=>'1','targetNumber'=>'13016760378']);
// //
// ////      return $RelationVerifyService->mobile3mQuery(['mobile'=>'18340910150','provider'=>'1']);
// //       return $RelationVerifyService->blackListQuery(['mobile'=>'17645184623','cert_no'=>'231225199903204016','cert_name'=>'韩所']);
// //       $data['result_code']=$relationRes['data']['resultCode'];
// //       $data['vcode']=$relationRes['data']['vcode'];
// //       return $data;
// //       exit();
// //       $res=MemberOther::where('create_time','>',time()-86400)->where('level_performance','<>','')->select('cert_no','level_performance')->get()->toArray();
// //       return json_encode($res);
// //        return WechatService::getSchemeUrl();
// //       $user= MemberOther::from('sp_member_2 as m')->where('m.openId','<>','')
// //            ->leftJoin('sp_bank_card as bc','m.id','bc.uid')
// //           ->leftJoin('sp_order_2 as o','o.uid','m.id')
// //           ->whereIn('o.status',['10','20','30','38','39'])
// //           ->where('bc.contract_no','<>','')
// //            ->select('m.id','bc.mobile_no')
// //            ->get()->toArray();
// //       foreach ($user as $key=>$item) {
// ////if($key==0){
// ////    continue;
// ////}
// //           $data = array();
// //           $data['content'] = '尊敬的用户，您好，由于系统升级，请重新设置绑卡，若不重新绑卡，可能会导致扣款失败影响信用,特此通知。weixin://dl/business/?t=knoxjsV044d';
// //           $send_res=SmsService::send_msg($item['mobile_no'],$data['content']);
// //
// //           if($send_res['status']){
// //               $send_status = 1;
// //               $reason = 'OK';
// //           }else{
// //               $send_status = 2;
// //               $reason = $send_res['msg'];
// //           }
// //
// //           $data['order_id'] = $item['trade_no'];
// //           $data['mobile'] = $item['mobile_no'];
// //           $data['member_id'] = $item['seller_id'];
// //           $data['template_id'] =26;
// //           $data['reason'] = $reason;
// //           $data['send_user'] = $item['uid'];
// //           $data['send_status'] = $send_status;
// //           $data['create_time'] = date('Y-m-d H:i:s');
// //           SmsRecord::insert($data);
// //           var_dump($send_res);
// //       }
// //
// //return $user;
// //        foreach ($user as $ra){
// //            $order_data=json_decode($ra['order_data'],true);
// //            OtherOrder::where('id',$ra['id'])->update(['trade_no'=>$order_data['trade_no']]);
// ////            dd($order_data['trade_no']);
// //        }
// //        exit();
// //
// //       $cert_no= Order::from('sp_order_2 as o')
// //           ->leftjoin('sp_member_2 as m','m.id','o.uid')
// //           ->where('o.create_time','>','1715270400')
// //           ->where('o.create_time','<','1715356800')
// //           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455'])
// //           ->distinct('m.cert_no')
// //           ->pluck('m.cert_no');
// //      return count($cert_no);
// //
// //       $user= Order::from('sp_order_lease_2')
// //           ->whereColumn('rent', '>', 'paid_rent') // 比较两个字段
// //           ->where('paid_rent','>','0')
// //           ->where('status',1)
// //           ->get()->toArray();
// //       return $user;
//        //取消订单
//        $user= Order::from('sp_order_2 as o')
//                ->where('o.status',4)
//                ->where('o.create_time','<','1720800000')
//                ->get()->toArray();
//   return count($user);
//        foreach ($user as $key=>$value) {
//            Order::where('id',$value['id'])->update(['status'=>1]);
//            $order=$value;
//            if (!empty($order['rights_auth_no']&&$order['alipay_trade_no'])&&$order['status']<=OrderService::ORDER_STATUS_PAY_SUCCESS) {//解冻预授权，作废合同
//                $alipay_data['alipayTradeNo'] = $order['alipay_trade_no'];
//                $alipay_data['authNo'] = $order['rights_auth_no'];
//                $prequery = AlipayService::alipayPreQuery($alipay_data);
//                if ($prequery['status']) {
//                    $rest_amount = $prequery['data']['rest_amount'];//订单总共剩余的冻结金额
//                    if ($rest_amount > 0) { //冻结金额大于0  执行解冻操作
//                        $thaw_data['amount'] = $rest_amount;
//                        $thaw_data['authNo'] = $order['rights_auth_no'];
//                        $thaw_query = AlipayService::alipayPreThaw($thaw_data);
//                        if ($thaw_query['status'] && $thaw_query['data']['code'] == AlipayService::ALIPAY_SUCCESS_CODE) { //解冻成功
//
//                        } else {
//                            return ['status' => CommonService::HTTP_CODE_FAIL, 'msg' => '授权资金解冻失败，请联系平台客服解决', 'data' => []];
//                        }
//                    }
//                } else {
//                    return ['status' => CommonService::HTTP_CODE_FAIL, 'msg' => '未查到授权资金解冻，请联系平台客服解决', 'data' => []];
//                }
//            }
//            var_dump($value['id']);
//        }
       exit();
//
////        return AlipayRiskService::levelPerformance('522624199606091815',1,0);
////
//       $user= Order::from('sp_order_2 as o')
//           ->where('o.status','39')
//           ->where('o.seller_id','1678175782')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->distinct('m.id')
//           ->select('m.mobile','m.cert_name','o.trade_no','o.id','o.uid','o.seller_id')
//           ->get()->toArray();
////      return count($user);
//       foreach ($user as $key=>$item) {
//           if($key==0){
//               continue;
//           }
//           $data = array();
//           $data['content'] = $item['cert_name'].':
//            根据《中华人民共和国合同法》和相关法律规定，及我方（淮北盈都网络科技有限公司）
//            与孝感租乐乐网络科技有限公司(以下简称新债权人)达成的债权转让协议，现将我方（淮北盈都网络科技有限公司）
//            对你方所享有的债权，依法转让给新债权人，与此转让债权相关的其他权利也一并转让。请'.$item['cert_name'].'自接到该债权转让通知书后应向新债权人履行全部义务。
//            特此通知。';
//           $send_res=SmsService::send_msg($item['mobile'],$data['content']);
//           var_dump($item['trade_no']);
//           var_dump($send_res);
//           if($send_res['status']){
//               $send_status = 1;
//               $reason = 'OK';
//           }else{
//               $send_status = 2;
//               $reason = $send_res['msg'];
//           }
//
//           $data['order_id'] = $item['trade_no'];
//           $data['mobile'] = $item['mobile'];
//           $data['member_id'] = $item['seller_id'];
//           $data['template_id'] =26;
//           $data['reason'] = $reason;
//           $data['send_user'] = $item['uid'];
//           $data['send_status'] = $send_status;
//           $data['create_time'] = date('Y-m-d H:i:s');
//           SmsRecord::insert($data);
//// break;
////         return ;
//        }
//      exit();
//
//
//
//               $res=AlipayRiskService::main();
//               dd($res);
////        $res=CreditCallService::remitInvestData('62896');
////
////       dd($res);
//       $res=CreditCallService::repayInvestData('62896','804506');
//       dd($res);
//       $res=CreditCallService::remitInvestData('49006');
//       dd($res);
//       $res=EsignService::createByUploadUrl();
//       dd($res);
//       exit();    ->offset(20)
//               ->limit(10)


           $orders= Order::from('sp_order_2 as o')
               ->where('o.sale_user_id','071013291497')
//               ->where('o.seller_id',1678175782)
               ->where('o.status',4)
//               ->where('o.create_time','<','1721145600')
//               ->where('o.create_time','>','1721102400')
               ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->select('*','o.id as order_id')
               ->orderBy('o.id','asc')->get();
           //推单

//       $orders=count($orders);
//    return $orders;
//       array_column($orders,'trade_no');

           foreach ($orders as $key=>$order_data){
//               dd($order_data);
//              if($key==0){
//                  continue;
//              }
               $member = MemberOther::where('id',$order_data['uid'])->first();

//               $age=getAgeByID($member['cert_no']);
//               if($age){
//                   if($age<22||$age>45){
//                       //return ['status' => CommonService::HTTP_CODE_FAIL, 'msg' => '您年龄不符合要求', 'data' => []];//，需要大于18岁小于40岁
//                       continue;
//                   }
//               }
               $contextId=$order_data['uid'];
               $log=$order_data;
               $log['order_id']=$order_data['order_id'];
               if($log['order_id']){
                   $ordercount=Order::from('sp_order_2 as o')
                       ->where('o.uid',$contextId)
                       ->where('o.seller_id','202309081070080001')//202405251855651266
                       ->count();
                   $otherordercount=otherOrder::where('trade_no',$order_data['trade_no'])->count();

                   if($ordercount==0&&$otherordercount==0){

//                       if($order_data['sale_user_id']=='061211271767'){
                           $otherMember= OtherOrderAllocate::where('member_id','202309081070080001')->first();
//                       }else{
//                           $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                           $otherMember = obToArray($otherMember);
//
//                           if(empty($otherMember)){
//                               OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
//                               $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                               $otherMember = obToArray($otherMember);
//                           }
//                       }


                       if($otherMember){
//                           if($otherMember['limit']){
//                               $order_limit_count=OtherOrder::where('member_id',$otherMember['member_id'])->whereDate('created_at', date('Y-m-d'))->count();
//                               if($order_limit_count>=$otherMember['limit']){
//                                   $otherMember=OtherOrderAllocate::whereRaw('limit = 0')->first();
//                               }
//                           }

                           OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                           $isSendOther=$otherMember['member_id']?1:0;
                       }else{
                           return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'订单创建成功');
                       }

                       $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');


                       $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
                       $order_lease_data=obToArray($order_lease_data);
                       $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
                       $goods = Goods::GoodsInfo($orderGoods['goods_id']);
                       $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
                       $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
                       $order_goods_data['goods']  = $goods;
                       $order_goods_data['goods_setmeal']  = $setmeal;
                       $order_goods_data['goods_spec'] =$spec;

                       if($isSendOther){
                           $order_data['order_from']='alipay_DH3';
                           if($order_data['sale_user_id']=='011615095213'){
                               $order_data['order_from']='alipay_DH1';
                           }
                           $add_remark = [
                               'uid'=>'23',
                               'username'=>'同步',
                               'create_time'=>time(),
                               'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
                               'order_id'=>$log['order_id']
                           ];
                           OrderRemark::insert($add_remark);
                           Order::where('id',$log['order_id'])->update(['username'=>'admin','seller_id'=>$otherMember['member_id']]);
                       }

                       $OtherOrder=[
                           'order_data'=>json_encode($order_data),
                           'order_lease_data'=>json_encode($order_lease_data),
                           'goods_data'=>json_encode($order_goods_data),
                           'member_data'=>json_encode($member->toArray()),
                           'remark_data'=>'[]',
                           'member_id'=>$otherMember['member_id'],
                           'order_id'=>$log['order_id'],
                           'trade_no'=>$order_data['trade_no'],
                           'status'=>1,
                           'from'=>1,
                           'is_allocate'=>1,
                       ];


                     OtherOrder::create($OtherOrder);
                       var_dump($order_data['trade_no']);
                   }
               }
           }

exit();
       $cert_no= Order::from('sp_order_2 as o')
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->where('o.create_time','>','1706198400')
           ->where('o.create_time','<','1710172800')
           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751'])
           ->distinct('m.cert_no')
           ->pluck('m.cert_no');
//       return $cert_no;
//     dd(count($cert_no));
//       var_dump(count($cert_no));
//       $ids=Db::table('sp_member_2')->whereIn('cert_no',$cert_no)
////           ->where('create_time','>','1698768000')
////           ->where('cert_no','<>','')
////           ->where('create_time','<','1701360000')
////           ->distinct('cert_no')->pluck('id');
////       var_dump(count($ids));
       $count=Order::from('sp_order_2 as o')
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->where('o.status','>',4)
           ->whereIn('m.cert_no',$cert_no)
           ->where('o.create_time','>','1706198400')
           ->where('o.create_time','<','1710172800')
//           ->select('m.cert_name','o.order_from')
//           ->get()
           ->count();
dd($count);
       return $count;


       $result=WechatService::get_order_list();
       $result=json_decode($result['data'],true);
       if($result['order_list']){
           foreach ($result['order_list'] as $ra){

               $where=[];
               $where[] =['ol.trade_no', $ra['transaction_id']];
               $where[] =['m.openId', '<>',''];
               $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
                   ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
                   ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
                   ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
                   ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
                   ->select(
                       'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
                       'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
                       , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
                       , 'm.mobile',
                   )->where($where)->orderBy('id','asc')->first();

//               dd($order);
               $OrderLease=OrderLease::where('out_order_no', $ra['transaction_id'])->where('which_period',1)->first();
               if($order&&$order['openId']&&$order['which_period']>1&&!$OrderLease){
                  WechatService::upload_shipping_info_lease($order,$ra['transaction_id'],$order['which_period']);
               }
           }
       }
       return $result;

       $wherea = [
           ['o.create_time','>=',strtotime("-1 hour")],
           ['o.order_from','wechat']
       ];
       $order = Order::from('sp_order_2 as o')->where($wherea)->where('o.status',OrderService::ORDER_STATUS_NOT_PAY)
           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
           ->select('o.id','o.uid','o.trade_no','o.rent_total','o.status','o.seller_id','m.cert_no','m.mobile','m.cert_name')
           ->limit(2000)
           ->get();
       $order = obToArray($order);
       dd($order);
       foreach ($order as $item) {
           $sms_template = SmsTemplate::where([['id',SmsTemplate::SMS_TEMPLATE_ORDER_AUTH_REMIND],['sms_status',ChargeService::SMS_TEMPLATE_STATUS_OPEN]])->value('clsms_content');

           $sms_content1 = str_replace('{$trade_no}', $item['trade_no'],$sms_template);
           $where1 = [];
//           $where1[] = ['template_id',SmsTemplate::SMS_TEMPLATE_ORDER_AUTH_REMIND];
           var_dump($item['trade_no']);
           $where1[] = ['order_id',$item['trade_no']];
           $count = SmsRecord::where($where1)->count('id');
           dd($count);
           if($count){
               continue;
           }
          $res=ChargeService::smsUse($item['seller_id'], $item['mobile'], $sms_content1, SmsTemplate::SMS_TEMPLATE_ORDER_AUTH_REMIND, $item['trade_no']);
       }

     dd($request['trade_no']);
       $order = Order::from('sp_order_2 as o')->where('o.trade_no',$request['trade_no'])
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->where('m.user_id','<>','')
           ->where('m.user_id','<>','0')
           ->orderBy('o.id', 'desc')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2','o.trade_no'
               ,'m.cert_name','m.cert_no','o.create_time'
               ,'m.mobile','m.user_id','m.idcard_front','m.idcard_back'
           )
           ->first();
       return InteractiveRiskQueryService::alipayRead($order['user_id'],$order['seller_id'],$order);

       $otherOrder=OtherOrder::where('member_id','202309081070080001')->where('order_id','=',0)->orderBy('order_id','asc')
           ->select('order_id','order_data')->get();
       $otherOrder=obToArray($otherOrder);
       $array=[];
       foreach ($otherOrder as $ra){
           $array[]=json_decode($ra['order_data'],true)['id'];
       }
//       dd($array);
       $orderIds=$array;
//     dd($orderIds);
//       foreach ($otherOrder as $ra){
           $res = Order::whereIn('old_order_id',$orderIds)->whereIn('status',['1','4'])->where('seller_id','<>','202309081070080001')->update(['seller_id'=>202309081070080001]);
           dd($res);
//           var_dump($ra['order_id']);
////           dd($ra['order_id']);
////           dd($ra['order_id'])
//       }
       $order = Order::from('sp_order_2 as o')->whereIn('m.mobile',['13953616317','13053666348',
           '18333684527','13693555142','15678886769','18163462797','13039573245','13053499699','15036598360','14754513591','15517388589','15154499271','18765153586','15720871175','15104834541','18606454333','18764653617','13258093316','15165445553','13053499699','17845080587','17845080587','17845080587','17671853582','13669139942','15763659591','13242070073','13242070073','13106751617','15123989775','13824789983','15014633715','19861313951','13827572910','18845961806','19122560324','13323976170','15866566671','17616832666','17277856775','17753614026','15394864619','18976865458','13288294929','18862834540','15910055704','15523396509','15264609865','17688830010','13048283699','15095248328','18366360312','15844695509','18550266881','14768669990','19653607455','19508441750','19508441750','18967269447','18967269447','15187012595','18376756247','13324416601','15982894689','18565187569','18583972141','15064416568','13476909946','18850230495','18672022537','17817388519','15294484400','15610256665','15089413963','15054430207','18706590651','19558561118','13045967915','15753671592','15854476210','18529165760','18583169185','18153544309','18671786275','15572726159','15169379894','19357079317','15621734477','15684631147','18087975120','15063639452','15621734477','18283530258','15106007981','15885674797','18718520723','19105363426','19305366454','18763652727','16695016787','18405363321','16652859087','16652859087','15773177767','19281919674','15095298333','19967911573','19109851273','13170233073','13170233073','15615666171','17852867213','18723253613','15854460087','15615660911','15169379894','18574242444','18762570870','17666546504','15621608868','15602369608','17319298354','15253655607','13145391996','18695615089','15725643200','18539351777','15074648387','19274782550','15621744378','18529295404','15216450700','15605362667','19005689775','15966132444','18056718701','15181558007','15777645424','17779384758','15526409329',
           '15669777008','15834426111','13049933335','15624222126','13842201315','18561950319'])
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->where('o.pact_url_2','<>','')
           ->orderBy('o.id', 'desc')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2','o.trade_no'
               ,'m.cert_name','m.cert_no','o.create_time'
               ,'m.mobile','m.idcard_back','m.idcard_front','o.pact_url_2','m.idcard_front','m.idcard_back'
           )
           ->get();
       $order = $order ? $order->toArray() : [];
       foreach ($order as $item) {
           $fileUrl = 'https://img.qianbaozuji.com/'.$item['idcard_front'];
//           dd($fileUrl);
           $fileName = $item['cert_name'].$item['idcard_front'];
           $file = file_get_contents($fileUrl);
           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/concact/'.$fileName;
           $a=file_put_contents($path,$file);

           $fileName = $item['cert_name'].$item['idcard_back'];
           $fileUrl = 'https://img.qianbaozuji.com/'.$item['idcard_back'];
           $file = file_get_contents($fileUrl);
           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/concact/'.$fileName;
           $a=file_put_contents($path,$file);
//           dd($a);
       }
       dd($a);



       $order = Order::from('sp_order_2 as o')->whereIn('m.mobile',['13953616317','13053666348',
           '18333684527','13693555142','15678886769','18163462797','13039573245','13053499699','15036598360','14754513591','15517388589','15154499271','18765153586','15720871175','15104834541','18606454333','18764653617','13258093316','15165445553','13053499699','17845080587','17845080587','17845080587','17671853582','13669139942','15763659591','13242070073','13242070073','13106751617','15123989775','13824789983','15014633715','19861313951','13827572910','18845961806','19122560324','13323976170','15866566671','17616832666','17277856775','17753614026','15394864619','18976865458','13288294929','18862834540','15910055704','15523396509','15264609865','17688830010','13048283699','15095248328','18366360312','15844695509','18550266881','14768669990','19653607455','19508441750','19508441750','18967269447','18967269447','15187012595','18376756247','13324416601','15982894689','18565187569','18583972141','15064416568','13476909946','18850230495','18672022537','17817388519','15294484400','15610256665','15089413963','15054430207','18706590651','19558561118','13045967915','15753671592','15854476210','18529165760','18583169185','18153544309','18671786275','15572726159','15169379894','19357079317','15621734477','15684631147','18087975120','15063639452','15621734477','18283530258','15106007981','15885674797','18718520723','19105363426','19305366454','18763652727','16695016787','18405363321','16652859087','16652859087','15773177767','19281919674','15095298333','19967911573','19109851273','13170233073','13170233073','15615666171','17852867213','18723253613','15854460087','15615660911','15169379894','18574242444','18762570870','17666546504','15621608868','15602369608','17319298354','15253655607','13145391996','18695615089','15725643200','18539351777','15074648387','19274782550','15621744378','18529295404','15216450700','15605362667','19005689775','15966132444','18056718701','15181558007','15777645424','17779384758','15526409329',
           '15669777008','15834426111','13049933335','15624222126','13842201315','18561950319'])
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->orderBy('o.id', 'desc')
           ->select(
               'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2','o.trade_no'
               ,'m.cert_name','m.cert_no','o.create_time'
               ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
           )
           ->get();
       $order = $order ? $order->toArray() : [];

//       var_dump(count($order));
//      return $order;
      $arr=[];
       foreach ($order as $item) {
           $result = EsignService::createIncestUserAuth($item);
           $flow_id = $result['data']['flowId'];
           $order_sign['flow_id_2'] = $flow_id;
           $res = Order::where('id',$item['id'])->update($order_sign);
           var_dump($item['trade_no']);
       }
       dd('a');

       $res=EsignService::createByUploadUrl();
       dd($res);
        $data['cert_name']='邴建礼';
        $data['mobile']='15393103307';
        $data['cert_no']='620123199407216118';
        $res=EducationService::queryRiskProbe($data);
       return $res;
       $url = 'http://tracking.e.qq.com/conv';
       $param = [
           'actions'=>[
               [
               "action_time"=>time(),
               "user_id"=>['wechat_openid'=>'oERTl5WG7JDTpNjmu3LWgNILPPF4','wechat_app_id'=>'wx19d3c0ddc53497ea'],
               "action_type"=>"REGISTER",
               "trace"=>['click_id'=>'123123'],
               "action_param"=>['value'=>'0'],
              ]
           ],
       ];

       var_dump(json_encode($param));
       $result = http_post($url,json_encode($param),['Content-type: application/json;charset=UTF-8']);
       $result = json_decode($result,true);
       dd($result);

       $res = AntchainService::templateCreate();
       dd($res);
//       $res=EsignService::createByUploadUrl();
//       dd($res);

//       $baofuPay=new BaofuWithdrawPayService();
//       $res=$baofuPay->pay();
//       dd($res);

        $baofuPay=new BaofupayService();
       $res=$baofuPay->SinglePay();
       dd($res);
        //汇付测试
//       $HuifupayService=new HuifupayService();
//
//        $res=$HuifupayService->quickbuckleWithholdApply();
//        dd($res);
//
//        //结算数据
//       $where[] = ['o.pay_type', '!=', Order::ORDER_PAY_TYPE_HUABEI];
//       $where[] = ['ol.status', OrderLease::ORDER_LEASE_STATUS_PAID];
//       $where[] = ['ol.settle_type', OrderLease::ORDER_LEASE_SETTLE_STATUS_YES];
//       $order = OrderLease::from('sp_order_lease_2 as ol')->where($where)
//           ->wherein('o.status', OrderService::getOrderStatus(OrderService::ORDER_SETTLE_CONFIRM_STATUS))
//           ->wherein('o.seller_id',['1678175782','1687342445','1690878551','1691726298'])
//           ->leftjoin('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->select('ol.id as lease_id', 'ol.order_id', 'o.trade_no', 'o.seller_id', 'o.month_total',
//               'ol.which_period', 'o.begin_time', 'o.end_time', 'og.goods_title', 'og.lease_set'
//               , 'og.lease_time', 'ol.begin_time as lease_time', 'ol.pay_type'
//               , 'ol.pay_time', 'ol.rent', 'ol.paid_rent', 'ol.status as lease_status',
//               'ol.settle_amount', 'ol.settle_time', 'o.realname', 'o.mobile',
//               'o.prov', 'o.city', 'o.area', 'o.address', 'o.financing_type',
//               'o.status as order_status', 'ol.overdue_days', 'ol.settle_type',
//               'ol.reason', 's.shopname', 'o.sync_status')->orderBy('ol.id', 'desc')->limit(1000)->get();
////       return $order;
////       dd($order);
//       $order = obToArray($order);
//       foreach ($order as $ra) {
//           $data['settle_type'] = OrderLease::ORDER_LEASE_SETTLE_STATUS_NO;
//           $data['settle_amount'] = '';
//           $data['settle_time'] ='';
//           $ol_res = OrderLease::where('id', $ra['lease_id'])->update($data);
////           var_dump($ra['lease_id']);
////           dd($ol_res);
//       }
//       exit();
//       $order = Order::from('sp_order_2 as o')
//           ->wherein('o.status', OrderService::getOrderStatus(OrderService::ORDER_SETTLE_STATUS))
//           ->where('o.seller_id', 1695898056)
//           ->select('o.id')->orderBy('o.id', 'desc')->pluck('o.id');
//       $order = obToArray($order);
//       return $order;
//       dd($order);

//             $order = Order::from('sp_order_2 as o')
//             ->wherein('o.status',OrderService::getOrderStatus(OrderService::ORDER_SETTLE_STATUS))
//             ->where('order_from','like','%wechat%')
//             ->where('create_time','>','1693497600')
//             ->select('o.id as lease_id','o.trade_no','o.id','o.pact_url')
//             ->orderBy('o.id','desc')->get();
//         $order=obToArray($order);
//
//       foreach ($order as $ra) {
//           $object = 'https://img.qianbaozuji.com/' . $ra['pact_url'];
//           var_dump($object);
//           $file = file_get_contents($object);
//           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/concact/' . $ra['pact_url'];
//           //               dd($path);
//           $res = file_put_contents($path, $file);
//           var_dump($res);
//       }
//exit();
//        $data['name']='黄秀珍';
//       $data['cert_no']='441284199412252549';
//        $res=EducationService::stableWealthReport($data);
//        dd($res);
       //百融法诉查询
//       $BairaongService=new BairaongService();
//       $res=$BairaongService->RequestInfoverify();
//       return $res;
//       $data['cert_name']='郑嘉豪';
//       $data['cert_no']='331003200001304114';
//       $data['mobile']='13575809157';
//       $BairaongService=new BairaongService();
//       $res=$BairaongService->limitQuery($data);
//       return $res;
//        //统计推单情况
       $cert_no= Order::from('sp_order_2 as o')
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->where('o.create_time','>','1698768000')
           ->where('o.create_time','<','1701360000')
           ->where('o.old_order_id','<>','0')
//           ->whereIn('o.order_from',['tingxiangzu','tingxiangzu-wechat','tingxiangzu-search','tingxiangzu-wechat2','tingxiangzu-saleOnline','tingxiangzu-douyin','tingxiangzu-qrcode'])
           ->distinct('m.id')
           ->pluck('m.cert_no');
//       return $cert_no;
//       dd($cert_no);
    var_dump(count($cert_no));
//       $ids=Db::table('sp_member_2')->whereIn('cert_no',$cert_no)
////           ->where('create_time','>','1698768000')
////           ->where('cert_no','<>','')
////           ->where('create_time','<','1701360000')
////           ->distinct('cert_no')->pluck('id');
////       var_dump(count($ids));
       $count=Order::from('sp_order_2 as o')
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->whereIn('o.status',OrderService::getOrderStatus(OrderService::ORDER_OVERDUE_COUNT))
           ->where('o.create_time','>','1698768000')
           ->whereIn('m.cert_no',$cert_no)
           ->select('m.cert_name','o.order_from')
           ->get()
           ->toArray();

       dd($count);
//
//       //e签宝更新租赁合同

//       //导出核对数据
//       $usera= Order::from('sp_order_2 as o')
//       ->where('o.status',30)
//       ->leftjoin('sp_member_2 as m','m.id','o.uid')
//       ->select('m.mobile','m.cert_name','m.cert_no','m.id')
//       ->distinct('m.id')
//       ->offset(20)
//       ->limit(10)
//       ->orderBy('m.id','asc')
//       ->get()->toArray();
//      var_dump($usera);
//       foreach ($usera as $ra){
//           YpcreditService::queryAssessment($ra);
//       }
//       exit();
//

       $usera= Order::from('sp_order_2 as o')
       ->where('o.status',30)
       ->leftjoin('sp_member_2 as m','m.id','o.uid')
       ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status')
       ->distinct('m.id')
       ->offset(20)
       ->limit(30)
       ->orderBy('m.id','asc')
       ->get()->toArray();

       $userb= Order::from('sp_order_2 as o')
           ->where('o.status',39)
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status')
           ->distinct('m.id')
           ->offset(20)
           ->limit(50)
           ->orderBy('m.id','asc')
           ->get()->toArray();

       $userc= Order::from('sp_order_2 as o')
           ->where('o.status',38)
           ->leftjoin('sp_member_2 as m','m.id','o.uid')
           ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status')
           ->distinct('m.id')
           ->limit(20)
           ->orderBy('m.id','asc')
           ->get()->toArray();


       $user=array_merge($usera,$userb,$userc);
       foreach ($user as $key=>$item) {
           $user[$key]['cert_name']=$item['cert_name'];
           $user[$key]['mobile']=$item['mobile'];
           $user[$key]['cert_name']=$item['cert_name'];
       }
      shuffle($user);
//       dd($user);

       $num = 0;
       $dataInfo=[];
       foreach ($user as $key=>$value) {
           $dataInfo[$key][] = $value['id'];
           $dataInfo[$key][] = " ".$value['trade_no']."\t";
           $dataInfo[$key][] = md5($value['cert_name']);
           // 日期
           $dataInfo[$key][] =md5($value['cert_no']);
           // 序号
           $dataInfo[$key][] = md5($value['mobile']);
           // 用户名
           $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);

           $num++;
       }

       $headList = [
           'id',
           '订单号',
           '姓名',
           '身份证',
           '手机号',
           '状态',
       ];

       $title = "导出cvs数据";

       //调用上面的方法
      return csvExport($dataInfo, $headList, $title);


       //虚拟发货
       $where[] =['ol.out_order_no', '4200002009202310313520835394'];
       $where[] =['m.openId', '<>',''];
       $where[] =['ol.out_order_no', '<>',''];
       $order = Order::from('sp_order_2 as o')
           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
           ->leftjoin('sp_order_return_2 as or', 'o.id', 'or.order_id')
           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
           ->select(
               'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','or.logistics_no','or.create_time','ol.which_period',
               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
               , 'og.goods_title', 'og.imgurl', 'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
               , 'm.mobile',
           )
           ->where($where)->orderBy('id','asc')->first();
//   return $order;
       if($order&&$order['openId']&&$order['which_period']>1){
          return WechatService::upload_shipping_info_lease($order,$order['which_period']);
       }
       return 0;

//       $res = AntchainService::templateCreate();//上传合同模板af9c2a002d7a4b83bd6a516e42197017
//       dd($res);
//       $res=EsignService::createByUploadUrl();
//      dd($res);
//       $where[] =['m.openId', '<>',''];
//       $where[] =['ol.out_order_no', '<>',''];
//       $orderList = Order::from('sp_order_2 as o')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->leftjoin('sp_order_return_2 as or', 'o.id', 'or.order_id')
//           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->select(
//               'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','or.logistics_no','or.create_time',
//               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.sign_status', 'o.guarantee_status', 'o.pact_url', 'o.is_skip', 'o.order_from'
//               , 'og.goods_title', 'og.imgurl', 'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//               , 'm.mobile',
//           )
//           ->whereIn('o.status',['30','20','38','39'])
//           ->where($where)->orderBy('id','asc')->get();
//       $orderList=obToArray($orderList);
////        dd($orderList);
//       foreach ($orderList as $ra){
//           WechatService::upload_shipping_info($ra);
//       }
//       return $orderList;
       //天创法诉查询
//       $array['cert_name']='许成楠';
//       $array['cert_no']='330183199506063214';
//       $array['mobile']='13456700054';
//       $array['id']='';
//       $res=YpcreditService::query($array);

//       dd($res);
       //创建商户
       $res= AntchainPlusService::registerBclMerchant();
       var_dump(obToArray($res));
       dd($res);
//       $res=SmsService::voiceMarketing('19357616167','2023-09-21 18:00:00|1000');
//       dd($res);






       //
       //$res=SmsService::sendCode(17779146889);
//       $a=explode(',','15128,5646,5647,5648,5649,5651,5652,5653,5654,5655,5657,5705,5706,5710,5712,5718,5719,5720,5721,5722,5723,5724,5725,5782,5783,5784,5788,5789,5790,5791,5792,5917,5918,5919,5920,5921,5922,5923,5924,5925,5926,5918,5919,5920,5921,5922,5923,5924,5925,5926,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,5705,5706,5710,5712,5718,5719,5720,5721,5722,5723,5724,5725,5782,5783,5784,5788,5789,5790,5791,5792,5917,5918,5919,5920,5921,5922,5923,5924,5925,5926,5918,5919,5920,5921,5922,5923,5924,5925,5926,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,22069');
//       $res= Order::where('seller_id',1677219996)
//           ->where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)
//           ->where('create_time','<',time()-86400*7)
////           ->select('id')
////           ->get()->toArray();
//           ->update(['status' => OrderService::ORDER_STATUS_CENCEL,'update_time'=>time()]);
//       return $res;

//       $sql= Order::where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)
//           ->whereBetween('create_time',[1690260941,1690282557])
//           ->select('id','uid','create_time', DB::raw('count(create_time) as created_at'))
//           ->having('created_at', '>', 1)
//           ->groupByRaw('uid,create_time')->get()->toArray();
//       foreach ($sql as $ra){
//           $res=Order::where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)->where('id',$ra['id'])->update(['status'=>OrderService::ORDER_STATUS_CENCEL]);
////         var_dump($res);break;
//       }
//       var_dump($sql);exit;
       //e签宝 通过上传方式创建模板
//       dd(66);
//  $res=OrderService::createThree([]);
//       $res=SmsService::sendCode(15994098637);
//       $orderId=5;
//       $certName='';
//       $certNo='a1aac87579b565c158e299396e16636c';
//       $mobile='fc490d20adee9000dfc31db3d19b6191';
//       $member_id=1660615608;
//    $res=RiskCredit::queryRiskCredit($orderId,$certName,$certNo,$mobile,$member_id);
//       $mobile='';
//       $code=123456;
//       $message = '您好，您的账户余额不足，担保合同充值失败，请尽快完成充值';
// $res=EsignService::createByUploadUrl();
// dd($res);
//       $res=AliyunSmsService::main('phone');
//       dd($res);
//       $res=ShopSms::orderRefundSuccess('1662369172','阿杰','20220907104014275167','手机号','3','1');
//       $fileName = "2ef168a1272f460fb076d08722cbe3f3_20230807152901.pdf";
//       $file = file_get_contents(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName);
//       $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;
//       $fileName="2ef168a1272f460fb076d08722cbe3f4.pdf";
//       file_put_contents($path,$file);
//       $uploud_res = AlipayService::upload($fileName,$path);
//      dd($uploud_res);
//       if($uploud_res['status']){
//           if(file_exists($path)){
//               unlink($path);
//           }
//       }
//      dd($path);
//       $res= AntchainService::download('789fb10ec56647c4a4b214fbb1bcdf78');
//       return $res;
//       $res=EsignService::downloadDocument('434d9705720f4eac911704b751ec3a9b');
//       return $res;
//       $order= Order::from('sp_order_2 as o')->where('o.id','28312')
//           ->leftjoin('sp_shop_user_2 as u','u.member_id','o.seller_id')
//           ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')
//           ->leftjoin('sp_member_2 as m','m.id','o.uid')
//           ->leftjoin('sp_order_return_2 as or','o.id','or.order_id')
//           ->select(
//               'o.id','o.uid','o.status','o.rent_total','o.month_total','o.foregift','o.seller_id','o.trade_no','o.realname','o.mobile as user_mobile','o.flow_id','o.amount','o.other_order_id','o.other_user_id','o.form_id','o.create_time','o.payer_user_id','o.begin_time','o.end_time','o.pay_type','o.order_from','o.is_skip','o.financing_type','o.is_renewal','o.parent_order_no','o.pact_url_2','o.pact_url_3'
//               ,'og.goods_title','og.lease_price','og.lease_set','og.goods_id','og.setmeal_id','og.spec_id','og.lease_time','og.start_date','og.imgurl','og.setmeal_foregift'
//               ,'m.cert_no','m.user_id','m.cert_name','m.cert_no','m.mobile','m.esign_user_id','m.esign_seal_id'
//               ,'u.shopname','or.logistics_no','u.is_guarantee','u.guarantee_amount','u.guarantee_minage','u.guarantee_maxage','u.mechanism'
//           )
//           ->first();
//       $order = $order ? $order->toArray() : [];
//       $order['rent_pay']=OrderLease::where('order_id',$order['id'])->orderBy('id','asc')->value('rent');
//       AlipayMessageService::sendChangeOrderMessage($order);
   }
   public function closeCopyOrder(){
      $sql= Order::whereBetween('create_time',[1689264000,1689334970])
           ->select('id', DB::raw('count(create_time) as created_at'))
           ->having('create_time', '>', 100)
           ->groupBy('uid')->get();
      var_dump($sql);
   }
   //线下支付 线上同步预授权订单
    public function payOffLine(){
        /*
        COMPLETE：同步用户已履约
        适用场景：发起扣款后，芝麻生成待履约记录，如果用户通过其他方式完成订单支付，请反馈该状态，芝麻将完结待履约记录对用户形成一条良好履约记录；

        CLOSED： 同步履约已取消
        适用场景：发起扣款后，芝麻生成待履约记录，如果发现该笔扣款无效需要取消，请反馈该状态，芝麻将取消用户待履约记录；

        VIOLATED： 用户已违约
        适用场景：如果用户在约定时间（具体根据行业约定，有一定宽限期）内未完成订单支付，反馈该状态，芝麻将对用户记录一条负面记录，请谨慎使用；

        sp_other_withhold_log表  使用order_no搜索
        */
        $orderData = [
            'orderId'    => '20221117130359667037', //order_no
            'outTradeNo' => '20221117130359667037|6551', //out_trade_no
            'tradeNo'    => '2022111722001400851425108003', //trade_no
            'status'     => 'COMPLETE',
        ];
        $res = AlipayService::orderInfo(10001, $orderData);

        dd($res);



    }
    //智能合同
    public function tests_templateCreate(Request $request){
exit();
        //主动支付退款
        $refund_data['amount'] =number_format('200', 2, '.', '');
        $refund_data['outTradeNo'] = 'B2025061719324157544910';
        $refund_data['tradeNo'] = '2025070222001421641452423859';
        $refund_data['out_request_no'] = '2025070222001421641452423859';
        $refund_res = AlipayService::alipayRefund('10008',$refund_data);
        return $refund_res;


//        $res=ShopSms::orderAuditSms('1678175782','20240415150511357862','17779146889');
//
//        return $res;
//        $refund_data['tradeNo'] = '2024041222001435721415378619';
//        $refund_data['outTradeNo'] = '20240412180916141706|1712916781';
//
//        $refund_data['amount'] = '0.01';
//       $refund_data['outTradeNo'] = '20240412180916141706|1712916781';
//       $refund_data['tradeNo'] = '2024041222001435721415378619';
//       $refund_data['out_request_no'] = '2024041222001435721415378619';
//        $refund_res = AlipayService::alipayRefund($refund_data);
//        dd($refund_res);

//            $flow_id='2bd51ad08e1f455aae3253479fd0d7b0';
//            $download_result = AntchainService::download($flow_id);
//            $fileUrl = $download_result['data'][0]['file_url'];
//            $fileName = $flow_id.".pdf";
//            $file = file_get_contents($fileUrl);
//            $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;
//           file_put_contents($path,$file);
//           dd($fileUrl);
//        $refund_res=WechatService::refund('202311131154039631088532','4200002015202311135159660106',
//            0.01*100,3187.60*100);
//dd($refund_res);

//        $order = OrderLease::from('sp_order_2 as o')
//            ->wherein('o.status',OrderService::getOrderStatus(OrderService::ORDER_SETTLE_STATUS))
//            ->where('og.pact_type',1)
//            ->where('o.is_insurance_choose','<>',7)
//            ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')
//            ->select('o.id as lease_id','o.trade_no','o.id','o.month_total')
//            ->orderBy('o.id','desc')->get();
//        $order=obToArray($order);
//       dd($order);
//        return $order;


        //导出商品图片
//        $goods = Goods::from('sp_goods_2 as g')
//            ->select('g.id','g.title','g.new_grade','g.rent_label','g.spread_title','g.imgurl','g.pact_type','g.min_price','g.min_lease_term','g.convey_type1', 'g.convey_type2','g.is_huabei','gd.images as carousel_images','gd.goods_content','su.is_show','su.photo','su.shopname','su.member_id','g.is_delete')
//            ->leftjoin('sp_goods_depict_2 as gd', 'gd.goods_id', '=', 'g.id')
//            ->leftjoin('sp_shop_user_2 as su', 'su.member_id', '=', 'g.member_id')
//            ->wherein('g.status',[GoodsService::GOODS_STATUS_PUT])
//            ->get();
//        $goods=obToArray($goods);
////       $goods=Category::where('image','<>','')->select('image')->get()->toArray();
//       foreach ($goods as $ra){
//
//           var_dump($ra);
//           $object = 'https://img.qianbaozuji.com/'.$ra['imgurl'];
//           var_dump($object);
//           $file = file_get_contents($object);
//           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$ra['imgurl'];
//           $res=file_put_contents($path,$file);
//           foreach (explode(',',$ra['carousel_images']) as $rb){
//               $object = 'https://img.qianbaozuji.com/'.$rb;
//               $file = file_get_contents($object);
//               $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$rb;
//               $res=file_put_contents($path,$file);
//               var_dump($res);
//           }
//        }
////
//  exit('a');
        // //查询征信
        // $input = $request->input();

        // if(!empty($input['orderId'])){
        //     $order = Order::from('sp_order_2 as o')->where('o.id',$input['orderId'])

        //         ->leftjoin('sp_member_2 as m','m.id','o.uid')
        //         ->select(
        //             'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2','o.trade_no'
        //             ,'m.cert_name','m.cert_no'
        //             ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
        //             )
        //         ->first();

        //     $order = $order ? $order->toArray() : [];

        //     if(empty($order['pact_url_2'])){
        //         //未签署个人征信授权书
        //         OrderService::createTwo($order);

        //     }

        //     //添加备注
        //     // $add = [
        //     //     'uid'=>$this->users['id'],
        //     //     'username'=>$this->users['username'],
        //     //     'create_time'=>time(),
        //     //     'remark'=>$this->users['username'].'查看征信',
        //     //     'order_id'=>$input['orderId']
        //     // ];
        //     // OrderRemark::insert($add);

        //     $risk_data = OrderCredit::getCreditData($input['orderId']);

        //     //有则输出，无则添加
        //     if($risk_data){
        //         if($risk_data['result2']){
        //             $code = json_decode($risk_data['result2'])->code;
        //             if($code == 0){
        //                 return ReturnMsg(CommonService::HTTP_CODE_FAIL,'正在查询征信，请稍等片刻再点击按钮');
        //             }else{
        //                 return ReturnMsg(CommonService::HTTP_CODE_FAIL,'征信查询有误，请联系挺想租客服处理');
        //             }

        //         }else{

        //             return ReturnMsg(CommonService::HTTP_CODE_FAIL,'征信查询有误，请联系挺想租客服处理');
        //         }

        //         //$risk_data['data'] = json_decode($risk_data['result'])->data;


        //     }else{
        //         //征信
        //         $risk_data = CreditService::getInvestData($order);
        //         // dd($risk_data);
        //         OrderCredit::setRiskData($input['orderId'],$risk_data,$order['cert_name'],$order['mobile'],$order['cert_no']);

        //         Order::where('id',$input['orderId'])->update(['is_credit_select'=>'2']);
        //         // $risk_data['cert_name'] = $order['cert_name'];

        //         // $risk_data['mobile'] = $order['mobile'];

        //         // $risk_data['cert_no'] = $order['cert_no'];

        //         // $risk_data['order_id'] = $input['orderId'];


        //         // $risk_data['start_at'] = date('Y-m-d H:i:s',time());

        //         // $risk_data['end_at'] =  date('Y-m-d H:i:s',time()+7*24*60*60);


        //         $online_data['user_type'] = OrderService::RISK_USER_TYPE_ADMIN; //管理员查看
        //         // var_dump($online_data);
        //         $online_data['username'] = "aq"; //查看人员

        //         OrderCredit::editCreditData($input['orderId'],$online_data);

        //     }

        //     // $res = obToArray($risk_data);

        //     return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'请求成功');

        // }else{
        //     return ReturnMsg(CommonService::HTTP_CODE_FAIL,'请选择要查询征信报告的订单');
        // }

//        $params['trade_no']='2023081622001420061449716525';
//        return AlipayService::alipayOrderPayQuery($params);

//        $shopData = [
//            'companyid'=>'91330381MAC65FWH5X',
//            'mechanism'=>'瑞安市诺明网络科技有限公司',
//            'member_id'=>'1662369172123',
//            'idcard'=>'330381198507130013',
//            'faname'=>'吴力军',
//            'id'=>'1233',
//        ];
//        $user_data = [
//            'idcard'=>'330381198507130013',
//            'user_mobile'=>'19357616167',
//            'user_name'=>'吴力军',
//            'user_id'=>'2088541530986955'
//        ];
//       $res=EsignService::addTerraceAccountId($shopData['companyid'],'',$shopData['idcard'],$shopData['companyid']);
//       dd($res);
        /*
        $shop = ShopUser::where('id',"1")->select('id','idcard','faname','mobile','companyid','mechanism','member_id')->first();
        $shop = obToArray($shop);
        $res = AntchainService::merchatCreate($shop);
        dd($res);
        */
       // $flow_id = '159380eab7814f7ea981e54d130da56b';
        // $res = AntchainService::userCreate($user_data); //电子合同平台方的用户注册  XMAUNLUF2088541530986955
        // $res = AntchainService::platformCreate(); //电子合同平台方注册
        // $res = AntchainService::merchatCreate($shopData);//注册  XMAUNLUF1662369172123   XMAUNLUF1662369172123
//      $res = AntchainService::merchantApply();//入驻
     //   $res = AntchainService::merchantEdit();//修改
        // $res = AntchainService::merchantimageCreate(); //上传图片
//         $res = AntchainService::merchantChess(); //进件审核
//        $res = AntchainService::merchantSelect(); //进件查询
   // $res = AntchainService::templateCreate();//上传合同模板af9c2a002d7a4b83bd6a516e42197017
////        // $res = AntchainService::merchantBind();//二级商户代理挂接接口
////       //  $res = AntchainService::contractFlowQuery($flow_id);//查询合同签署情况
 //  dd($res);

        // $order = Order::where('flow_id',$flow_id)->select('id','trade_no','sign_status','status','other_order_id','other_user_id')->first();
        // $order = obToArray($order);
        // // //合同下载
//         $download_result = AntchainService::download($flow_id);
         // dd($download_result);
        // if($download_result['status']){
        //     $fileUrl = $download_result['data'][0]['file_url'];
        //     $fileName = $flow_id.".pdf";
        //     $file = file_get_contents($fileUrl);
        //     $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;

        //     file_put_contents($path,$file);
        //     $uploud_res = AlipayService::upload($fileName,$path);
        //     if($uploud_res['status']){
        //         if(file_exists($path)){
        //             unlink($path);
        //         }
        //     }
        //     $order_data['pact_url'] = $fileName;
        //     $order_data['sign_status']  = EsignService::ESIGN_STATUS_FINISH;
        //     Order::where('id',$order['id'])->update($order_data);
        // }

        /*
        $flag = false;
        $shopId = 4;
        $shop = ShopUser::where('id',$shopId)->select('id','idcard','faname','mobile','companyid','mechanism','member_id')->first();
        $shop = obToArray($shop);
        if($shop){
            $res = AntchainService::merchatCreate($shop);
            dd($res);
            if($res['status']){
                $ant_user_id = $res['data'];
                $shopRes = ShopUser::where('id',$shopId)->u中华人民共和国合同法pdate(['ant_user_id'=>$ant_user_id]);
                if($shopRes){
                    $flag = true;
                }
            }
        }
        return $flag;
        */
//        $res=AntchainService::payRule('29a93236cfba452b9b325b252e846908'); //查看规则
//        $data=json_decode($res['data'],true);
//        dd($data);


//        $order=order::where('status',1)->where('flow_id','<>',0)->whereNull('sign_no')->select('flow_id','status','trade_no','id')->get()->toArray();
////dd($order);
//        foreach ($order as $key=>$ra){
//            $res = AntchainService::payRule($ra['flow_id']); //查看规则
//            $data=json_decode($res['data'],true);
////            if($res['status']&&$data['userSign']==true){
////
////               $resa = AntchainService::paytradeCancel($ra['flow_id']); //取消智能合同剩余代扣条目
//////                    var_dump($ra['trade_no']);
//////                    dd($resa);
////                var_dump($resa);
//                $dataInfo[$key][] = "\t".$ra['trade_no'];
//                $dataInfo[$key][] = OrderLease::where('order_id',$ra['id'])->where('status',1)->sum('rent');
////            }
//        }
//
//        $headList = [
//            '订单号',
//            '金额',
//        ];
//        $title = "取消订单";
//
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
//exit();
//        return AntchainService::payUnbind('2088222143177531_99f199ea01684701','XMAUNLUFT1065');

      // $res = AntchainService::payRule($flow_id); //查看规则
       //  $res = AntchainService::paytradeCancel($flow_id); //取消智能合同剩余代扣条目
       //d5d51d72f8b948169abae0d7a1aad2de

       $flow_id = 'a541bc42900342009439a736be840c93';//a8be703ee9454f298ffdfab8b1240506
//  $res = AntchainService::paytradeCancel($flow_id);//取消智能合同剩余代扣条目
////
//         $out_request_no = 'a541bc42900342009439a736be840c93_4_73';
//         $out_trade_no = 'a541bc42900342009439a736be840c93_4_73';//3ede968b9cbf498baf53de445339f723_2_31
//         $refund_amount = '42272';
//         $res = AntchainService::merchantRefundCreate($flow_id,$out_request_no,$out_trade_no,$refund_amount); //退款
////  return $res;
////       $res = AntchainService::tradeDetail($flow_id,$out_trade_no); //查看详情规则
//
//        //$res = AntchainService::paysingletradeExec($flow_id,$out_trade_no); //触发代扣
//     return  $res = AntchainService::contractRefundQuery($out_request_no); //查询退款
//      return $res;
        //     $res = AntchainService::contractTradeStatusQuery($out_trade_no); //代扣规则状态查询根据代扣订单号查询单笔代扣规则状态详情。

        // $res = AntchainService::callbackkeyApply(); //4d484c5e27cc2028fd7fbbe28a447bbb
//  $res = AntchainService::paysingletradeCancel($flow_id,$out_trade_no); //取消智能合同某一期代扣条目
        $res = AntchainService::payRule($flow_id); //查看规则

        return $res;

//     $res = AntchainService::payRule($flow_id); //查看规则
        //$data=json_decode($res['data'],true);
//  var_dump($data['payRules'][0]['outTradeNo']);
//   return $res;
//    dd($res);

        //主动支付退款
        $refund_data['amount'] = '958.23';
        $refund_data['outTradeNo'] = '20241009115913417246|1728464446';
        $refund_data['tradeNo'] = '2024100922001490611425987468';
        $refund_data['out_request_no'] = '2024100922001490611425987468';
//        $refund_res = AlipayService::alipayRefund($refund_data);
      $refund_res = AlipayService::alipayRefundDetail(0, $refund_data);
   return $refund_res;
//       dd($refund_res);

        //退款测试
        // $arr = ['55921'];
        // echo '<pre>';
        // print_r($arr);
        // $lease_res = OrderLease::whereIn('id',$arr)->update(['status'=>OrderLease::ORDER_LEASE_STATUS_REFUNDED,'refund_time'=>date('Y-m-d H:i:s')]);
        // dd($lease_res);
        /*
        //雷达
        $data = [
            'cert_name'=>'李四',
            'cert_no'=>'110102200101017072',
            'mobile'=>'15099996666',
            'order_no'=>'123456764534578'
        ];
        $res = RadarService::radarData($data);
        dd($res);
        */

        //外部请求订单

        // $res = RadarService::getOtherOrder();
        // dd($res);


        // $res = ShopSms::orderPlaceSendToShop('1677219996','啊啊','2354432');

        // dd($res);


        //征信

        //签署授权书


        $input = [
            'cert_name'=>'',
            'cert_no'=>'',
            'order_no'=>'12312312',
            'mobile'=>''
        ];
        // $res = CreditService::getInvestData($input);

        // dd($res);
        /*
        //创建法人账号
        // $res = EsignService::addFaAccountID('1','吴力军','330381198507130013','19357616167');
        // dd($res);
        //个人征信授权书
        $order = Order::from('sp_order_2 as o')->where('o.id','163')
                ->leftjoin('sp_member_2 as m','m.id','o.uid')
                ->select(
                    'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2'
                    ,'m.cert_name','m.cert_no'
                    ,'m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
                    )
                ->first();
        $order = $order ? $order->toArray() : [];
        // $result = EsignService::addPersonAccountID($order['cert_no'],$order['cert_name'],$order['cert_no'],$order['user_mobile']);
        // dd($result);
        $res = OrderService::createTwo($order);
        dd($res);
        */
        /*
        //用户授权协议
        $order = Order::from('sp_order_2 as o')->where('o.id','164')
                ->leftjoin('sp_member_2 as m','m.id','o.uid')
                ->select(
                    'o.id','o.uid','o.mobile as user_mobile','o.pact_url_2','o.pact_url_3'
                    ,'m.cert_name','m.cert_no','m.mobile','m.esign_user_id','m.esign_seal_id','m.user_id','m.idcard_front','m.idcard_back'
                    )
                ->first();
        $order = $order ? $order->toArray() : [];
        $res = OrderService::createOne($order);
        dd($res);
        */
        /*
        //融资租赁协议
        $order = Order::from('sp_order_2 as o')->where('o.id','163')
                ->leftjoin('sp_shop_user_2 as u','u.member_id','o.seller_id')
                ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')
                ->leftjoin('sp_member_2 as m','m.id','o.uid')
                ->select(
                    'o.id','o.uid','o.status','o.rent_total','o.month_total','o.foregift','o.seller_id','o.trade_no','o.realname','o.mobile as user_mobile','o.flow_id','o.amount','o.other_order_id','o.other_user_id','o.form_id','o.create_time','o.payer_user_id','o.begin_time','o.end_time','o.pay_type','o.order_from','o.is_skip','o.financing_type','o.is_renewal','o.parent_order_no','o.pact_url_2','o.pact_url_3'
                    ,'og.goods_title','og.lease_price','og.lease_set','og.goods_id','og.setmeal_id','og.spec_id','og.lease_time','og.start_date','og.imgurl','og.setmeal_foregift'
                    ,'m.cert_no','m.user_id','m.cert_name','m.cert_no','m.mobile','m.esign_user_id','m.esign_seal_id'
                    ,'u.shopname','u.is_guarantee','u.guarantee_amount','u.guarantee_minage','u.guarantee_maxage','u.mechanism'
                    )
                ->first();
        $order = $order ? $order->toArray() : [];
        $res = OrderService::createThree($order);
        dd($res);

        */
        //上传sftp
        // $res = CreditService::login("rarmwl", "rarmwl@2023#03.10@",'https://img.qianbaozuji.com/857efae685e348c0980f335fc375312c.pdf','/2023/1.pdf');
        // dd($res);

        // CreditService::login("rarmwl", "rarmwl@2023#03.10@",'https://img.qianbaozuji.com/a09fc616d0c74020b66ac44001a3fa6f.pdf','/2023/a09fc616d0c74020b66ac44001a3fa6f.pdf');

        //上报征信
        // $res = CreditService::applyInvestData();
        // dd($res);
        // $request =[];
        // $data = Order::creditOrderList();
        // dd($data);


        //合同下载
        $flow_id = '2d72eb63067e4f268867678e5742204e';
        $download_result = AntchainService::flowStart($flow_id);

        //$download_result = AntchainService::contractFlowQuery($flow_id);
        // $download_result = AntchainService::getSignurl('XMAUNLUFT2508',$flow_id);
         //$download_result = AntchainService::flowSave($flow_id);
        // $download_result = AntchainService::download($flow_id);
        dd($download_result);
        if($download_result['status']){
            $fileUrl = $download_result['data'][0]['file_url'];
            $fileName = $flow_id.".pdf";
            $file = file_get_contents($fileUrl);
            $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;

            file_put_contents($path,$file);
            $uploud_res = AlipayService::upload($fileName,$path);
            // dd($uploud_res);
            if($uploud_res['status']){
                if(file_exists($path)){
                    unlink($path);
                }
            }
            $order_data['pact_url'] = $fileName;
            $order_data['sign_status']  = EsignService::ESIGN_STATUS_FINISH;
            Order::where('id','8782')->update($order_data);

        }


        //获取签署地址
        // $order = Order::from('sp_order_2 as o')->leftjoin('sp_member_2 as u','o.uid','u.id')->leftjoin('sp_shop_user_2 as su','o.seller_id','su.member_id')->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->leftjoin('sp_goods_2 as g','og.goods_id','g.id')->where('o.id','163')->select('o.id','o.uid','o.seller_id','o.is_insurance_choose','o.flow_id','o.mobile','o.user_email','o.sign_num','o.address','o.trade_no','o.rent_total','o.month_total','o.amount','o.realname','o.rent_total','o.foregift','o.status','u.ant_user_id','u.mobile as user_mobile','u.id as x_user_id','u.cert_name','u.user_id','u.cert_no','og.pact_type','og.is_buy_out','og.goods_title','og.setmeal_title','og.lease_set','og.setmeal_price','og.setmeal_foregift','og.goods_id','og.setmeal_id','og.spec_id','o.begin_time','o.end_time','og.lease_price','og.lease_time','o.sign_status','su.mechanism','su.faname','su.contact_tel','su.company','su.company_area','su.companyid','g.new_grade','u.esign_user_id','og.website_price','o.prov','o.city','o.area','su.ant_user_id as mer_ant_id','og.start_date')->first();
        // $order = obToArray($order);
        // OrderService::getSignUrl($order);

        // $order_from = 'tingxiangzu';

        // $arr = explode('-',$order_from);

        // dd($arr);

        // $res= RadarService::setDeliverOrder($mobile);
        /*
        $fileName = '20230220150054493212.jpg';
        $fileUrl = 'https://img.tingxiangzu.com/'.$fileName;
        $file = file_get_contents($fileUrl);
        $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;
        dd(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
        file_put_contents($path,$file);
        $uploud_res = AlipayService::upload($fileName,$path);
        dd($uploud_res);
        */
        //同步发货状态
        //同步订单状态

        // $orders = Order::where('status','39')->select('mobile','id')->get();
        // $orders = obToArray($orders);
        // // dd($orders);
        // // $orders = Order::where('id','407')->select('mobile')->get();
        // foreach($orders as $order){
        //     $mobile = $order['mobile'];
        //     $order_arr = Order::where('mobile',$mobile)->select('id','order_from','old_order_id')->get();
        //     $order_arr = obToArray($order_arr);
        //     foreach($order_arr as $value){
        //         $order_from = $value['order_from'];
        //         $order_from_arr = explode('-',$order_from);
        //         // if($order_from_arr[0] == 'tingxiangzu'){
        //             //发送数据
        //             // echo $value['id'].'<br>';
        //             // dd($order);
        //             $res = RadarService::setDeliverOrder($mobile,$value['old_order_id'],'30');
        //             print_r($res);
        //         // }

        //     }
        // }

        /*
        $complainEventId = '2023053000102000000013756549'; //支付宝投诉单号
        $res = AntchainService::complain($complainEventId);
        // dd($res);
        if($res['status']){
            //添加数据
            $insertData = [
                'complainEventId'=>$res['data']['complain_event_id'],
                'status'=>$res['data']['status'],
                'tradeNo'=>$res['data']['trade_no'],
                'merchantOrderNo'=>$res['data']['merchant_order_no'],
                'gmtCreate'=>$res['data']['gmt_create'],
                'gmtModified'=>$res['data']['gmt_modified'],
                'gmtFinished'=>!empty($res['data']['gmt_finished'])?$res['data']['gmt_finished']:'',
                'leafCategoryName'=>$res['data']['leaf_category_name'],
                'complainReason'=>$res['data']['complain_reason'],
                'content'=>$res['data']['content'],
                'images'=>json_encode($res['data']['images']),
                'phoneNo'=>$res['data']['phone_no'],
                'tradeAmount'=>$res['data']['trade_amount'],
                'replyDetailInfos'=>json_encode($res['data']['reply_detail_infos']),
                'resultCode'=>$res['data']['result_code'],
                'resultMsg'=>$res['data']['result_msg'],
                'reqMsgId'=>$res['data']['req_msg_id']
            ];
            // dd($insertData);
            Complain::insert($insertData);
            echo '成功';
        }else{
            echo '失败';
        }
        die;
        */
    }


 public function exportOrder(){
        $ressult=Db::table('sp_other_order_2')->whereDate('created_at','2023-9-18')->where('is_allocate',1)->limit(100)->orderBy('created_at','desc')->get();
     $ressult=obToArray($ressult);
//        dd($res);
        // dd(COUNT($res['data']));
     $i=0;
        if($ressult){ //成功
            foreach($ressult as $data){
                //请求订单数量
                $order_count = COUNT($res['data']);
                $order_data = json_decode($data['order_data'],true);

                $res=Db::table('sp_other_order_2')->where('id',$data['id'])->decrement('is_allocate');

//                if(Redis::get('TradeNo'.$order_data['trade_no'])){
//                    continue;
//                }
                var_dump('begin'.$data['id']);
                if(Order::where('trade_no',$order_data['trade_no'])->value('id')){
                    continue;
                }

                $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->select('member_id','limit','id')->first();
                $otherMember = obToArray($otherMember);

var_dump('allow'.$data['id']);

                if(empty($otherMember)){
                    OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->select('member_id','id')->first();
                    $otherMember = obToArray($otherMember);
                }
                if($order_data&&$otherMember){
                    if($otherMember['limit']){
                        $order_limit_count=OtherOrder::where('member_id',$otherMember['member_id'])->whereDate('created_at', date('Y-m-d'))->count();
                        if($order_limit_count>=$otherMember['limit']){
                            $otherMember=OtherOrderAllocate::whereRaw('limit = 0')->first();
                        }
                    }
                    $OtherOrder=[
                        'order_data'=>$data['order_data'],
                        'order_lease_data'=>$data['order_lease_data'],
                        'goods_data'=>$data['goods_data'],
                        'member_data'=>$data['member_data'],
                        'remark_data'=>$data['remark_data'],
                        'member_id'=>$otherMember['member_id'],
                        'order_id'=>$order_data['id'],
                        'status'=>1,
                        'is_allocate'=>1
                    ];
                    OtherOrder::create($OtherOrder);
                    OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                    $isSendOther=$otherMember['member_id']?1:0;
                }
//                dd($isSendOther);
                $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');

                $order_lease_datas = json_decode($data['order_lease_data'],true);
                $goods_data = json_decode($data['goods_data'],true);
                $member_data = json_decode($data['member_data'],true);
                $remark_data = json_decode($data['remark_data'],true);
                // dd($order_lease_datas);

                // if(!empty($order_data) && !empty($order_lease_datas) && !empty($goods_data) && !empty($member_data)){
                if(!empty($order_data) && !empty($goods_data) && !empty($member_data)){
                    $this->upload_img($order_data['imgurl']);
                    $this->upload_img($member_data['idcard_front']);
                    $this->upload_img($member_data['idcard_back']);

//                dd($order_lease_datas);
                    //会员资料
                    $cert_no = $member_data['cert_no'];
                    $member = MemberOther::where('cert_no',$cert_no)->select('id')->first();
                    $member = obToArray($member);
                    if($member){
                        $uid = $member['id'];
                    }else{

                        $add_member_data = [
                            'mobile'=>$member_data['mobile'],
                            'user_id'=>isset($member_data['user_id'])?$member_data['user_id']:0,
                            'cert_name'=>$member_data['cert_name'],
                            'cert_no'=>$cert_no,
                            'idcard_front'=>$member_data['idcard_front'],
                            'idcard_back'=>$member_data['idcard_back'],
                            'head_image'=>$member_data['head_image'],
                            'nick_name'=>$member_data['nick_name'],
                            'gender'=>$member_data['gender'],
                            'province'=>$member_data['province'],
                            'city'=>$member_data['city'],
                            'status'=>'1',
                            'create_time'=>time(),
                            'update_time'=>time()
                        ];
                        //ceshi123
                        $uid = MemberOther::insertGetId($add_member_data);//会员ID
                    }
                    $goods_detail = $goods_data['goods'];
                    // dd($goods_detail);
                    $goods_setmeal_detail = $goods_data['goods_setmeal'];
                    $goods_spec_details = $goods_data['goods_spec'];

                    // $goods_title = $goods_detail['title'];
                    // $goods = Goods::where('title',$goods_title)->select('id')->first();
                    // $goods = obToArray($goods);
                    // if($goods){
                    //     $goods_id = $goods['id'];
                    // }else{
                    //商品
                    $add_goods_data = [
                        'title'=>$goods_detail['title'],
                        'new_grade'=>$goods_detail['new_grade'],
                        'member_id'=>'1687342445',
                        'category_id'=>'0',
                        'status'=>'2',
                        'pay_type'=>'1',
                        'ischeck'=>'4',
                        'is_delete'=>'1',
                        'create_time'=>time(),
                        'update_time'=>time(),
                        'is_show'=>'2'
                    ];
                    //ceshi123
                    $goods_id = Goods::insertGetId($add_goods_data);//商品ID
                    // }
                    //商品套餐
                    $add_goods_setmeal_data = [
                        'goods_id'=>$goods_id,
                        'title'=>$goods_setmeal_detail['title'],
                        'quantity'=>$goods_setmeal_detail['quantity'],
                        'foregift'=>$goods_setmeal_detail['foregift'],
                        'price'=>$goods_setmeal_detail['price'],
                        'create_time'=>time()
                    ];
                    //ceshi123
                    $setmeal_id = GoodsSetmeal::insertGetId($add_goods_setmeal_data);//商品套餐ID
                    //商品套餐详情
                    foreach($goods_spec_details as $goods_spec_detail){
                        $add_goods_spec_data = [
                            'lease_time'=>$goods_spec_detail['lease_time'],
                            'setmeal_id'=>$setmeal_id,
                            'lease_price'=>$goods_spec_detail['lease_price'],
                            'withhold_cycle'=>$goods_spec_detail['withhold_cycle'],
                            'day_price'=>$goods_spec_detail['day_price'],
                            'goods_id'=>$goods_id
                        ];

                        //ceshi123
                        $spec_id = GoodsSpec::insert($add_goods_spec_data);//商品套餐ID
                    }
//                $spec_id=1;
                    //订单
                    $add_order_data = [
                        'seller_id'=>'1687342445',
                        'username'=>$isSendOther?'admin':'tingxiangzu',
                        'uid'=>$uid,
                        'trade_no'=>$order_data['trade_no'],
                        'is_insurance_choose'=>$order_data['is_insurance_choose'],
                        'rent_total'=>$order_data['rent_total'],
                        'month_total'=>$order_data['month_total'],
                        'amount'=>$order_data['amount'],
                        'payment'=>$order_data['payment'],
                        'remark'=>$order_data['remark'],
                        'realname'=>$order_data['realname'],
                        'mobile'=>$order_data['mobile'],
                        'address'=>$order_data['address'],
                        'pay_time'=>$order_data['pay_time'],
                        'prov'=>$order_data['prov'],
                        'city'=>$order_data['city'],
                        'area'=>$order_data['area'],
                        'begin_time'=>$order_data['begin_time'],
                        'end_time'=>$order_data['end_time'],
                        'payer_user_id'=>$order_data['payer_user_id'],
                        'user_email'=>$order_data['user_email'],
                        'old_order_id'=>$order_data['id'],
                        'status'=>OrderService::ORDER_STATUS_SIGN_NOCHECK,
                        'create_time'=>time(),
                        'update_time'=>time(),
                        'pay_type'=>'1',
                        'order_from'=>'tingxiangzu-'.$order_data['order_from'],
                        'foregift_deduct'=>$order_data['foregift_deduct'],
                        'foregift_pay'=>$order_data['foregift_pay']
                    ];
                    //ceshi123
                    $order_id = Order::insertGetId($add_order_data);//订单ID
                   // var_dump($order_id);
//                dd($order_id);
                    //ceshi123
                    $res_set = RadarService::setOtherOrder($order_count,$order_data['id']);
                    //风控备注
                    if($remark_data){
                        foreach($remark_data as $remark_value){
                            $add_remark_data = [
                                'uid'=>'23',
                                'username'=>'同步',
                                'create_time'=>time(),
                                'remark'=>$remark_value['remark'].'(风控建议)',
                                'order_id'=>$order_id
                            ];
                            OrderRemark::insert($add_remark_data);
                        }
                    }

                    $add_remark = [
                        'uid'=>'23',
                        'username'=>'同步',
                        'create_time'=>time(),
                        'remark'=>'同步订单',
                        'order_id'=>$order_id
                    ];
                    OrderRemark::insert($add_remark);

                    if($isSendOther==1){
                        $add_remark = [
                            'uid'=>'23',
                            'username'=>'同步',
                            'create_time'=>time(),
                            'remark'=>'订单已推给其他平台',
                            'order_id'=>$order_id
                        ];
                        OrderRemark::insert($add_remark);
                    }
                    //订单商品
                    $add_order_goods_data = [
                        'order_id'=>$order_id,
                        'goods_id'=>$goods_id,
                        'goods_title'=>$order_data['goods_title'],
                        'imgurl'=>$order_data['imgurl'],
                        'setmeal_id'=>$setmeal_id,
                        'setmeal_title'=>$order_data['setmeal_title'],
                        'spec_id'=>$spec_id,
                        'lease_set'=>$order_data['lease_set'],
                        'lease_time'=>$order_data['lease_time'],
                        'lease_price'=>$order_data['lease_price'],
                        'setmeal_price'=>$order_data['setmeal_price'],
                        'setmeal_foregift'=>$order_data['setmeal_foregift'],
                        'start_date'=>$order_data['start_date'],
                        'pact_type'=>$order_data['pact_type'],
                        'is_buy_out'=>$order_data['is_buy_out'],
                        'create_time'=>$order_data['create_time'],
                        'device_number'=>$order_data['device_number'],
                        'website_price'=>$order_data['website_price'],
                        'seller_id'=>'1687342445'
                    ];
                    //ceshi123
                    OrderGoods::insert($add_order_goods_data);

                    //订单租期
                    foreach($order_lease_datas as $order_lease_data){
                        $add_order_lease_data = [
                            'order_id'=>$order_id,
                            'which_period'=>$order_lease_data['which_period'],
                            'rent'=>$order_lease_data['rent'],
                            'begin_time'=>$order_lease_data['begin_time'],
                            'end_time'=>$order_lease_data['end_time'],
                            'create_time'=>$order_lease_data['create_time']
                        ];
                        //ceshi123
                        OrderLease::insert($add_order_lease_data);
                    }

                    $authenticLog = AuthenticLog::where('order_id',$order_id)->select('id')->first();
                    $authenticLog = obToArray($authenticLog);
                    if($authenticLog){
                        //已有认证资料

                    }else{
                        //认证资料
                        $add_authentic_data = [
                            'order_id'=>$order_id,
                            'certify_id'=>'1',
                            'status'=>'1',
                            'cert_no'=>$cert_no,
                            'cert_name'=>$member_data['cert_name'],
                            'idcard_front'=>$member_data['idcard_front'],
                            'idcard_back'=>$member_data['idcard_back'],
                            'create_time'=>date('Y-m-d H:i:s')
                        ];
                        //ceshi123
                        AuthenticLog::insert($add_authentic_data);
                    }
                    var_dump('id'.$order_id);
                    var_dump($i++);
                }
            }
            \Illuminate\Support\Facades\Log::debug('订单同步任务执行成功',$ressult);

        }else{ //提示

            \Illuminate\Support\Facades\Log::debug('订单同步任务执行失败',['订单同步任务执行失败']);
        }

    }


//    public function upload_img($fileName){
//        $fileUrl = 'https://img.tingxiangzu.com/'.$fileName;
//        // echo $fileUrl;
//        // dd(file_exists($fileUrl));
//        if(!empty($fileName)){
//            // echo $fileUrl."\r\n";
//            $file = file_get_contents($fileUrl);
//            $path = dirname(dirname(dirname(dirname(dirname(__FILE__)))) ). '/storage/tmp/'.$fileName;
//
//            file_put_contents($path,$file);
//            $uploud_res = AlipayService::upload($fileName,$path);
//            // print_r($uploud_res);
//            // dd($uploud_res);
//            if($uploud_res['status']){
//                if(file_exists($path)){
//                    unlink($path);
//                }
//            }
//        }
//
//    }

    public function upload_img($fileUrl){
        $path = parse_url($fileUrl, PHP_URL_PATH);

// 获取路径的文件信息
        $fileName = pathinfo($path, PATHINFO_BASENAME);
        if(!empty($fileName)){
            // echo $fileUrl."\r\n";
            $file = file_get_contents($fileUrl);
         $path = dirname(dirname(dirname(dirname(dirname(__FILE__)))) ). '/storage/tmp/'.$fileName;

            file_put_contents($path,$file);
            $uploud_res = AlipayService::upload($fileName,$path);
            return $fileName;
            // dd($uploud_res);

        }

    }


}
